Reverse post order
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…
September 23rd, 2008 at 9:56 pm
It seems to only work if you make the quotes single ie: ‘&order=ASC’
September 24th, 2008 at 5:25 am
Actually, it depends on your server configuration. On my server, it works fine with double quotes: “&order=ASC”
November 7th, 2008 at 8:54 am
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.
November 7th, 2008 at 8:08 pm
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.
February 13th, 2009 at 1:13 am
Yeah, except that mine doesn’t have
February 15th, 2009 at 11:27 am
http://www.thegirlintheredsweater.com – great domain name for blog like this
February 16th, 2009 at 2:01 pm
http://www.thegirlintheredsweater.com – cool sitename man)))
————————
my blog: http://sudeg.ru/
February 17th, 2009 at 9:04 am
http://www.thegirlintheredsweater.com – now in my rss reader)))
————————
my blog: http://potet.ru/
May 2nd, 2009 at 3:13 pm
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
May 2nd, 2009 at 3:14 pm
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’);
May 2nd, 2009 at 3:52 pm
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.
June 28th, 2009 at 8:57 pm
I used this code to do the exact opposite… arrange entries from most recent to least. PHP scares me. Thanks for the tip
August 26th, 2009 at 1:19 pm
[...] Reversing the post order in WordPress Hi, Kim. I haven’t tried it, but according to this post, here’s the scoop: [...]
August 29th, 2009 at 8:13 am
Good article. I’ll definitely try to incorporate this into my own blog.
November 5th, 2009 at 12:33 pm
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.
November 13th, 2009 at 5:03 pm
Works a treat, thanks for posting this. Needed to find the index.php of my theme used (wp-content/themes)
February 9th, 2010 at 3:31 am
Thanks soooo much…fast easy and not techno geek speak.
Blessings!
February 9th, 2010 at 6:25 am
Glad it was helpful!
June 15th, 2010 at 11:56 pm
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”);
—
June 16th, 2010 at 1:47 pm
Thanks for sharing! It’s always nice to have multiple ways to achieve the same basic effect.
July 11th, 2010 at 2:47 pm
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.
July 12th, 2010 at 9:42 am
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”);
—
July 12th, 2010 at 6:51 pm
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.