Have you ever wanted to display random posts (portfolio items) in your sidebar similar to my site?
Well today I am going to quickly show you how this is done.
First of all you will to create a category to hold all your portfolio items. Then create your portfolio items as “posts” and place them in the category you just created.
Now you have the framework for which to begin pulling these posts in a random order.
Begin by opening up “sidebar.php” in your theme folder. We will be using a WordPress custom loop to achieve our goal.
$port_items = new WP_Query();
$port_items->query('showposts=3&category_name=portfolio&orderby=rand');
The info that is passed to the query is the important part.
showposts=3 : Only show 3 posts
category_name=portfolio : only show posts within the specified category
orderby=rand : show in random order
You would then proceed with the normal WordPress Loop and display the information however you need.
while($port_items->have_posts()): // display here endwhile;
This has been your quick tip today. What other tips would you like to learn about? Share them in the comments!
September 7th, 2011 at 2:07 pm
Thank you! i was trying to put my category post random, and with your help, i had get it!
Regards!
Twitter
Follow me on Twitter to keep up to date!
RSS Feed
Keep up with all of our updates by subscribing to our RSS feed!
FaceBook
Join our group on Facebook and become a fan of us!