Home | Contact | Videos | MediaZo

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

<ul>
  <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

<ul>
  <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 .


Honey Singh is Head of Operations & Strategic Planning at MediaZo. He has an experience of 5 years in designing, ideating/operating digital/social marketing strategies for global brands. You can also catch him on Foursquare, Twitter, Facebook , Google+ & Instagram.

30 Responses to “How to show Random posts without using any WordPress plugins”

  1. How to show Random posts without using any #Wordpress plugins http://is.gd/2uWFp

  2. How to show Random posts without using any #Wordpress plugins http://is.gd/2uWFp

  3. How to show Random posts without using any WordPress plugins http://bit.ly/10yeHV

  4. hey, nice code, just what I need, thank you

  5. How to show Random posts without using any WordPress plugins http://bit.ly/8boNHD

  6. How to show Random posts without using any WordPress plugins http://bit.ly/8boNHD #wordpress

  7. How to show Random posts without using any WordPress plugins http://bit.ly/8boNHD #wordpress

  8. Nice quick tip – RT @pkruvczuk: How to show Random posts without using any WordPress plugins http://bit.ly/8boNHD #wordpress

  9. wow only your code works on my blog thank you so much..

    check here:

    h++p://pspwallpaper.cz.cc/search/psp+wallpaper+cloud.html

  10. Hi! Yeah, like Indra said, only your code works! I tried 3 others and they don’t seem to work. Thanks!

  11. it shows the same post 5 times. not working for me.

  12. 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 “

  13. i was a former employee and now i am making my best effort to start up a small business.*;.

  14. thank you.. nice sharing

  15. nice artile really usefull for every theme.i checked it on 3 different themes. thanks again

  16. thank you for code, great post

  17. When I apply random post bellow the title, the content random too. How to fix this ?

  18. 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.”,

  19. thank you for post, nice sharing.. good works!

  20. 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…

  21. 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!

  22. I saw but how did you defined a category in the above code ?
    I mean I can’t see any category code there.

  23. @Shaz3e You can add category_name=you-category-name in the above code. Check the updated post!

  24. its great help honey singh keep it up

  25. 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 :P

  26. Where Do I add this code???

  27. Hey thanks for adding the code.. I was in need for this..

  28. I can’t implement it with my thesis theme. Please help

  29. 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

Leave a Reply


+ one = two