How to list oldest posts first

Blogs traditionally have shown newest posts first: that ease of finding what's new is arguably what's made them so popular with both writers and readers. But there are times when you'll want to list posts in the other order: oldest first. If you're using WordPress as a content management system and building content in categories, your first post might be the most important, so you'll want it at the top of the category archive, for example.

Happily you only need to add one line of code to do this, and here it is:

<?php query_posts($query_string."&order=ASC"); ?>

Add this to the theme file you want to change: normally search.php for search results, archive.php for category and date archives, or index.php for the front page (this might vary according to how your theme is organised). You need to add it before the loop starts, so look for <?php if (have_posts()) : ... and add it before that.

Share this post:
  • email
  • del.icio.us
  • Facebook
  • FriendFeed
  • LinkedIn
  • StumbleUpon
  • Tumblr
  • Twitter

Tags: ,

Posted by Sue on April 28, 2009 in WordPress.

4 comments to "How to list oldest posts first"

  1. Jason wrote:

    you don't know how long I have search for that bit of code,, thanks!

  2. Shasta wrote:

    That was just precisely the thing! (And not easy to find on the WordPress official sites...)

Tweetbacks

  1. New blog post: How to list oldest posts first http://tinyurl.com/daetur (via @Biddy)

Leave a Reply