scooter girl

Reverse post order

Oct 06, 2007 15:10

By default, WordPress shows your posts in order of most recent to oldest. Call me crazy, but sometimes I’d rather show older posts first and tack the newest ones on at the bottom.

After searching for quite some time through WordPress.org and Google, I finally stumbled upon the key piece of code.

In your index.php file, look for this bit of code:

<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>

Right before that line, add this code:

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

That’s it, that’s all there is too it! Code is so lovely when you find the right one for your purposes…



23 Responses to “Reverse post order”

  1. Stu Says:

    It seems to only work if you make the quotes single ie: ‘&order=ASC’

  2. thegirl Says:

    Actually, it depends on your server configuration. On my server, it works fine with double quotes: “&order=ASC”

  3. themover Says:

    Stu thanks very much for this tip, i was checking wordpress.org for a while now and didn’t get this out.

    This is not depending on the server it is just a copy and paste failure. If you copy the line above and paste it in your code you’re getting no “normal” double quotes. Sorry no idea how to call them.

  4. thegirl Says:

    It looks like the problem was this blog using “smart quotes” (slanted quotes) by default. I have updated the code with normal quotes so you can now copy and paste without having to edit anything.

  5. Brandon M. Sergent Says:

    Yeah, except that mine doesn’t have

  6. AeromiHoosizegngj Says:

    http://www.thegirlintheredsweater.com – great domain name for blog like this

  7. kathSnall Says:

    http://www.thegirlintheredsweater.com – cool sitename man)))
    ————————
    my blog: http://sudeg.ru/

  8. Neoggexytig Says:

    http://www.thegirlintheredsweater.com – now in my rss reader)))
    ————————
    my blog: http://potet.ru/

  9. hermit Says:

    Hi – I too would like to put my posts in ‘natural’ order instead of the bizarre, back-tofront style which is defualt; however, my index.php only says this:

    So, where does the code go??

    Congratulations on your new arrival!!

    Great site, love the name.

    Best wishes,

    Jim

  10. hermit Says:

    Hey, what happened to my code??

    /**
    * Front to the WordPress application. This file doesn’t do anything, but loads
    * wp-blog-header.php which does and tells WordPress to load the theme.
    *
    * @package WordPress
    */

    /**
    * Tells WordPress to load the WordPress theme and output it.
    *
    * @var bool
    */
    define(‘WP_USE_THEMES’, true);

    /** Loads the WordPress Environment and Template */
    require(‘./wp-blog-header.php’);

  11. thegirl Says:

    Hermit, looks like you are using a template with nonstandard coding. I can’t tell from what you posted where you need to put this code to change the post order; it might be in a different file. If you can post all the code from your index.php file here I’ll see if I can figure out where you need to look.

  12. Michael Babbish Says:

    I used this code to do the exact opposite… arrange entries from most recent to least. PHP scares me. Thanks for the tip

  13. Reversing the post order in Wordpress - WarriorForum - Internet Marketing Forums Says:

    [...] Reversing the post order in WordPress Hi, Kim. I haven’t tried it, but according to this post, here’s the scoop: [...]

  14. sweatersbuy. Says:

    Good article. I’ll definitely try to incorporate this into my own blog.

  15. dyno Says:

    Thank you!

    This was fantastic… I was looking for a way to display posts in natural date order for printing and didn’t find any. After ur tip, I added “&order=ASC” to the end of an URL did the trick.

  16. chris Says:

    Works a treat, thanks for posting this. Needed to find the index.php of my theme used (wp-content/themes)

  17. Casandra Says:

    Thanks soooo much…fast easy and not techno geek speak.

    Blessings!

  18. thegirl Says:

    Glad it was helpful! :)

  19. Doug Says:

    Thanks!

    I also found this helpful tip on the WordPress site.


    …to set the display order of the posts without affecting the rest of the query string, you could place the following before The Loop:

    global $query_string;
    query_posts($query_string . “&order=ASC”);

  20. thegirl Says:

    Thanks for sharing! It’s always nice to have multiple ways to achieve the same basic effect.

  21. Rob S. Says:

    I have been trying to get this code to work with the new twenty ten default theme for WordPress 3.0 and can’t for the life of me figure it out.

    It does what it is supposed to on the first page of posts but it seems to be looping the older post and newer post links back to the first page of posts.

    They have added some new functions to the loop for the twenty ten theme so I am wondering if some of those functions are causing the problem.

  22. thegirl Says:

    They did make some major adjustments in WP 3.0, and this particular code was designed to be used in version 2.x. Did you try Doug’s suggestion from the WP site?


    …to set the display order of the posts without affecting the rest of the query string, you could place the following before The Loop:

    global $query_string;
    query_posts($query_string . “&order=ASC”);

  23. Erroline Says:

    Thank you. I’ve been searching for this information on and off for months. It works. Much appreciated. Like everybody else, really liking the name.

Leave a Comment