The Personal Weblog of Akshay Jain
Recently, I was creating one website in which there were loads of database entries which I needed to integrate into Wordpress Blogging system as it is really flexible.
But the default option of Wordpress is that it always shows all the posts in reverse chronological order but I wanted to change posts order so that the posts on the front page is displayed in an ascending order.
For achieving this, either you can use good plugins that are currently available which allow you to get a greater control of your posts but I found them very complicated and they were meant for more complicated things than just arranging the posts in ascending order.
So, here is a little code that I found which you can place in your /wp-content/themes/THEMENAME/index.php file. You have to place it just before the posts loop code which will basically look something like this:
Just add the following code just before “if(have_posts())“ and your posts will be arranged in an ascending order.
query_posts($query_string."&order=ASC");
Hope that helps someone who is looking for this code. If you have any other Wordpress queries, then you can make a comment on this post.
I am Akshay Jain a student in Economics and a web enthusiast. Most of my readers would be knowing me by my pseudonym champ_rock/champrock. This is my blog and I know I wont be keeping this updated. For contacting me, please use the contact form!
Please subscribe to the RSS feeds in order to get the latest updates on my blog!
WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.
Alex
October 11th, 2008 at 5:30 am
Hey, I was trying to do this very thing and found that just putting in your code did not work but when I added the around it, it worked perfectly.
Thanks for your work!
Akshay Jain
October 11th, 2008 at 6:24 am
Great that worked for u. It worked directly for me. Please post what changes you made so that I can have a better look at it.
JC
November 4th, 2008 at 7:44 pm
Is this what the code is supposed to look like? It’s not working for me.
Let me know if I’m doing something wrong - this solution seems much easier than installing a plugin so I hope I can get it to work!
Sonny Gill
November 4th, 2008 at 7:49 pm
Hi Akshay,
I’m having this issue the reverse way as my posts on a new custom theme are showing oldest post first. Would I be able to add your code with DESC instead of ASC to offset this? Any other theme I’ve had works fine but this new one. Very strange.
A snippet of my code where ‘have_posts’ appears, looks like this:
Where would I have to include your code?
Appreciate your help!
Best,
Sonny
Sonny Gill
November 4th, 2008 at 9:02 pm
Nevermind, totally worked! Thanks so much!
Rydall
December 20th, 2008 at 9:23 pm
It also did not work for me the first time but with a little bit of tweaking, it worked perfectly. For those who are not too familiar with PHP. follow Akshay’s instructions but the code should look like this :
Thanks for this post Akshay. It was a life saver. I was trying to sort this out for the past few days and was just not too happy with any plugins.