How to show Random posts without using any WordPress plugins
Displaying the “Random posts” in your blog is the best ways to drag the users/ viewers attentions and hence helps in optimizing the bounce rates of your website. There are many plugins which display the random posts like Random Posts Widget ,Advanced Random Post ,Random Posts ,AJAX Random Posts ,Random Posts from Category ,Randomizer ,Random Featured Post and several others. Apart from these plugins you can also use light custom code to get the random posts which work on simple MySQL RAND() function to sort the random post using parameter values.
Code for displaying random posts in wordpress template
<li>
<h2>Random thougths of my blog</h2>
<ul>
<?php
$rand_posts = get_posts('numberposts=5&orderby=rand');
foreach( $rand_posts as $post ) :
?>
<li><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></li>
<?php endforeach; ?>
</ul>
</li>
</ul>
Showing Posts from categories
<li>
<h2>Random</h2>
<ul>
<?php
$rand_posts = get_posts('category_name=Uncategorized','numberposts=5','orderby=rand');
foreach( $rand_posts as $post ) :
?>
<li><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></li>
<?php endforeach; ?>
</ul>
</li>
</ul>
Note: You can use the above code anywhere in your wordpress templates. If you like this post then must go through the 101 List Of Awesome WordPress Tips and Resources .
We're powered by ProjectManager.com –
August 23rd, 2009 at 8:01 pm
How to show Random posts without using any #Wordpress plugins http://is.gd/2uWFp
August 23rd, 2009 at 8:01 pm
How to show Random posts without using any #Wordpress plugins http://is.gd/2uWFp
August 24th, 2009 at 8:23 pm
How to show Random posts without using any WordPress plugins http://bit.ly/10yeHV
December 9th, 2009 at 8:09 am
hey, nice code, just what I need, thank you
December 27th, 2009 at 7:08 pm
How to show Random posts without using any WordPress plugins http://bit.ly/8boNHD
January 22nd, 2010 at 1:52 am
How to show Random posts without using any WordPress plugins http://bit.ly/8boNHD #wordpress
January 22nd, 2010 at 2:38 am
How to show Random posts without using any WordPress plugins http://bit.ly/8boNHD #wordpress
January 22nd, 2010 at 2:41 am
Nice quick tip – RT @pkruvczuk: How to show Random posts without using any WordPress plugins http://bit.ly/8boNHD #wordpress
January 31st, 2010 at 9:18 am
wow only your code works on my blog thank you so much..
check here:
h++p://pspwallpaper.cz.cc/search/psp+wallpaper+cloud.html
March 26th, 2010 at 3:04 am
Hi! Yeah, like Indra said, only your code works! I tried 3 others and they don’t seem to work. Thanks!
April 9th, 2010 at 7:27 am
it shows the same post 5 times. not working for me.
May 2nd, 2010 at 10:49 pm
i have tried social media marketing for getting our new products to be known on the market. it seems to work well specially if the audience is targeted “
May 19th, 2010 at 10:41 am
i was a former employee and now i am making my best effort to start up a small business.*;.
October 13th, 2010 at 10:34 pm
thank you.. nice sharing
October 16th, 2010 at 6:47 am
nice artile really usefull for every theme.i checked it on 3 different themes. thanks again
November 11th, 2010 at 7:59 pm
thank you for code, great post
December 8th, 2010 at 1:00 am
When I apply random post bellow the title, the content random too. How to fix this ?
December 9th, 2010 at 1:59 pm
Thank you very much for sharing this info…I’m quite having a hard time on how to show random posts…actually everything is alien to me…but I wanted to learn since I wanted to write blogs. It is really helpful, hoping you’re up for more.”,
January 4th, 2011 at 12:49 pm
nice
also look at
http://anewtab.com/display-wordpress-random-posts-without-any-plugin
for similar posts
January 21st, 2011 at 3:03 am
thank you for post, nice sharing.. good works!
April 1st, 2011 at 1:07 am
Its great and nice trick but what should I do I have to use it twice in my theme and I am thinking for some advance method, perhaps I can use random posts form specific categories twice recently I tried query_post which is not working if you could help me with your method it will be appreciated…
April 2nd, 2011 at 4:39 pm
I have used the same code twice in a single page for showing posts from different categories. Check the posts in footer of this blog!
April 3rd, 2011 at 1:52 am
I saw but how did you defined a category in the above code ?
I mean I can’t see any category code there.
April 3rd, 2011 at 2:27 am
@Shaz3e You can add category_name=you-category-name in the above code. Check the updated post!
April 3rd, 2011 at 2:34 am
its great help honey singh keep it up
April 3rd, 2011 at 2:45 am
instead of your code I was trying to show my post randomly in the sidebar and static post at the footer one of them was working at a time but now I got my problem solved will provide a demo as soon as I launches a website Thanx Honey thanx again man, you saved my life
May 16th, 2011 at 9:43 am
Where Do I add this code???
June 21st, 2011 at 4:04 pm
Hey thanks for adding the code.. I was in need for this..
July 16th, 2011 at 2:42 am
I can’t implement it with my thesis theme. Please help
July 16th, 2011 at 7:17 pm
Good post
With the dawn of Google checking page speed it is important to diminish the use of Plugins and hand code instead
Your post helps me tremendously to limit ise of plugins
Greg