New Addition – Random Posts

Random Posts
A few weeks ago, my friend Santhosh posted a nice little tutorial on noob2geek on how to display random posts on your wordpress blog. I was thinking about implementing it on this blog for a long time, finally I got some free time and I have implemented the feature here on this blog.
I have made a few changes to the code given on that post on noob2geek. I wanted to display random posts at the bottom of every individual post. The method on n2g does 2 things, 1 is that it displays even the current post in the random posts. Secondly, it does not work well in-line to a post as we don’t store the $post variable anywhere. Hence, the code with the changes is given below.
<!-- ************ Random Posts **************** --> <h2>Other Posts You Might Like</h2> <ul> <?php global $post; $tmp_post = $post; $rand_posts = get_posts('exclude='.get_the_ID().'&numberposts=4&orderby=rand'); foreach( $rand_posts as $post ) : ?> <li><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></li> <?php endforeach; ?> <?php $post = $tmp_post; ?> </ul> <!-- *********** Random Posts ************** -->
Hmm… The code looks a bit weird in blockquotes. I might have to change the way a block quote is displayed. Right now, check the wp-syntax version. Other’s are not working, unfortunately.
Other Posts You Might Like
- And I Started Loving Oscars Again
- Of Connection Issues and Test Scores
- Coffee
- Miserable State of Roads
This entry was posted on Friday, March 5th, 2010 at 20:24 and is filed under Announcement. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
I am, a Linux fanatic, a nature photographer, a music fiend… I spend most of my time these days listening to Music while browsing the Internet about various topics of my interest ranging from Electronics to coffee recipes. Learn more about me 


Aditya March 5th, 2010 at 21:25
No idea mate. Stopped using Blogger LONG time ago.