How to: Randomize posts order

February 2, 2009 at 8:00 am

Are you building a portfolio or a gallery with WordPress? If yes, it can be a good thing to randomize posts order, just like I did on the footer of WpRecipes.com theme to display WordPress themes. That’s very easy to do with WordPress: Just read on.

To randomize posts order, you’ll have to use the very powerful query_posts() function before your WordPress loop:

query_posts('orderby=rand');
//Your loop goes here

Of course, it is also possible to randomize only a certain category:

query_posts('cat=10&orderby=rand');
//Your loop goes here