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.
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
11 Responses
Great suggestion. Thanks for the tip!
It works fine on parent category but when viewing child/sub category it shows all post from parent (meaning all sub category posts). Suggestions? Thanks.
Great recipe, as always!
Great recipe here. It’s going to really help with this theme idea I’ve had for a while. Thanks a load. Didn’t even think this was possible.
Thanks for that, great bit of code!!
Hey!
Just wondering if you are able to add this into a category page? I tried it, but it displayed all categories on a page, not the category I was on.
I see you put that you can add the cat id to the query, but I have at least 30 categories, so wondering if there is a quicker way to do it instead of doing conditional tags for each category.
Thanks
Stacey
thanks for this solution. I have specific theme and sometimes I’ve troubles with some function, for example some plugins doesn’t work, but I’ll try use this code.
Thanks
Dekoracje Tort
Trackbacks: