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!
airtel
apple
apple itunes
ascii
benchmark
broadband
browser
confidence motion
converter
ebaumsworld
firefox
fun
galwaysidle
Google
google campus ambassador
google gadget
google trends
google trends hacked
google trends spam
gtalk
hacked
hijack
how to poop at work
idle
iim
iim-i
iim pgp
iim student website
image to ascii
indian government
ipod
itunes
latest browsers
opera
opera functions
politics
ram
ram usage
redirect
swastika
taskmanager
trends hacked
typo
virus
ǝlƃooƃ noʎ ʞɔnɟ Broadband (India) (2)
Code Snippets (6)
Economics (1)
General (18)
Google (3)
Indian Politics (1)
Jainism (1)
Kindle Touch (1)
Latest Buzz (6)
New Scripts (1)
opera (2)
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton 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.
mdnicerio
January 22nd, 2009 at 7:36 pm
Thanks …. man
Just plain simple…
arenecute
June 12th, 2009 at 5:09 pm
wow! this is INDEED HELPFUL!!!
thanks loadsssssssssssssss
<3
Joe Botha
July 7th, 2009 at 9:43 pm
Something else that may come in handy when working with this is the ability to display posts organized by title in ascending order.
&orderby=title&order=asc
Nancy Hall
July 20th, 2009 at 11:55 pm
Hi Akshay,
I am new to working with code. I tried to insert this code in the index file but it didn’t change the order of the posts. Actually, the line showed up on the site! : S lol! I inserted your suggested code snippet before the the line you mentioned – not sure why it didn’t work.
Can you tell me which ap you are using with that lovely moving tag cloud (cool) – I’ve got 2.8.2 version of wp now. Thank you!!! : )
Kam
December 29th, 2009 at 11:43 am
Thankyou! works great!
Brit Whittington
January 12th, 2010 at 12:00 am
This worked for me as well, but how do I get the top post (oldest post) to move off the page when a new post is created (comes in at the bottom). Right now the oldest post remains at the top of the page and new posts are being moved to the next page.
Brit Whittington
January 12th, 2010 at 12:44 am
I ended up using the ‘Post Filter’ plug-in that allows me to hide posts from the FrontPage. Unless you know of a more automated way to get it to move items off the page from the top rather than the bottom.
fasil
April 15th, 2010 at 4:36 am
Alhamdulilala………………Nice …………………thank …………………
But on the time of pasting this code you should be care full on the queres Here it is mentioned
query_posts($query_string.”&order=ASC”);
But actuall is
query_posts($query_string. “&order=ASC”);
” ” , ” ” .. see these are different………any way thank you very much
Aaron
August 28th, 2010 at 9:10 pm
I am having a problem with one of my sites. This is a template that I have used a few times, all of the sites work just fine, the posts display like default in DESC order the way I want. But this one site, no matter what I do I cannot get it to display in DESC order. It displays in ASC order even when I put in DESC. I copied and pasted this line from a site that works and it still displays in ASC.
This is the site that is broken: http://vaporshopper.info
This is a site using the same template that works: http://dragonfly.realecig.com
I need vaporshopper to work like the dragonfly site, in DESC order. I tried adding the date back in but it did not change. I am totally stumped, I cannot figure out what is making it display in ASC order even when I tell it to display in DESC order.
These two sites are essentially the same except for the content and some colors. Can you think of anything else that may make it display in ASC order and ignore the line when I tell it to display in DESC order?
Bnw
October 15th, 2010 at 9:14 am
Nice! It took me two days to find your post and fix my problem using one line of code…. That sucks =D
Finally my posts(movies) are arranged as they should be.
mike
December 17th, 2010 at 11:16 pm
can you give an example of the code so i can see exactly how you placed it in the code before “if have post”. i tried putting it in and it didnt work for me? i am using the church theme for me blog. thanks.
Nicholas Barnard
April 2nd, 2011 at 2:51 pm
One other thing, if you’re using this on a page that has links to the next and previous page in the series, make sure to switch
previous_posts_link and next_posts_link — for most themes you should change the function, not the text that is referencing.
xnet84
April 19th, 2011 at 1:51 am
thank you so much!!!!!!!
Lesley
May 26th, 2011 at 6:00 am
Thanks for this – worked a treat!!
re7ox
September 5th, 2011 at 8:16 pm
Thanks a lot. The current theme I’m working with wasn’t allowing the switch. Simple line of code from your article and now its working.
Much Appreciated ^_^
Dewitt Padiong
November 18th, 2011 at 7:16 pm
My partner and I stumbled over here different page and thought I might as well check things out. I like what I see so i am just following you. Look forward to checking out your web page for a second time.
Learn to make use of Search engine marketing Wp Plugin
March 18th, 2012 at 2:59 am
Learn to make use of Search engine marketing Wp Plugin…
[...]Arrange Posts in ascending order WordPress – Akshay Jain[...]…