Displaying a Complete Archive on One Page in WordPress

Today, I tried to solve a seemingly simple problem on the Walter and Ina site. Of course, a seemingly simple computer problem can quickly turn into a huge time-suck, and that’s exactly what happened. I’m betting there’s at least one other person out there who’d like to know how to do the same thing, so I’m posting my solution. If you don’t maintain your own WordPress site, just move along – nothing to see here.

The problem: I wanted a page on the site that would display a complete archive of all previous posts, in chronological order (oldest post first). The Walter and Ina blog, for those just tuning in, is a collection of letters my grandparents exchanged during their forty-year relationship. New visitors wanted to be able to read the whole set from the beginning to the latest posting. Simple enough, right?

Here’s how to do it. First, create a page template – mine is called chronology.php. Save this in your WordPress theme folder. The template code is in this text file. If you download that link instead of copying and pasting it, you’ll need to change the extension to .php before uploading it to your theme directory.

The crux of the matter is this line:

<?php query_posts('order=asc&posts_per_page=-1'); ?>

That says to query the database for posts in ascending order, and load them all onto one page – for some reason, loading “minus one” means loading them all. Following that is the loop to spit out all of the posts, and then the sidebar and footer.

Once you’ve uploaded the page template, just log into your site and create a new page. There’s a pull-down menu in the right sidebar of the editing screen where you can choose a page template. Your new one (called “Chronology” if you just copied the text file) should appear there. Choose it. Give the page a title, but don’t put anything in the content box. Save it.

Now visit your new page. It should be a complete archive of all previous posts, oldest first.

While writing this post, I discovered that the default WordPress options for preformatted and code-formatted text are pretty lame. Should be simple to fix, right?

Maybe I’d better quit while I’m ahead.