Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » WordPress / WordPress Snippets » How To Display Random Posts In WordPress Without A Plugin?

How To Display Random Posts In WordPress Without A Plugin?

Because of the natural structure regarding blogs, articles turn out to be buried down if they get old. Most new users join and pick up as soon as they join, and they also never bother returning to college to one of your respective good posts. One of many easiest way to provide a new life to your older posts can be by displaying them inside sidebar. In this kind of tutorial, we will share ways to display random posts with your WordPress.

It is also a powerful snippet to get more page views on your blog like you can add a heading of trending to it so on every reload this list of posts will be changed and the visitor click every time a new post and will think that its really now tending. You can also add the heading that last visit saw this so you current visitor will also see that what was other last visiting as its human natures so its upto you to garb your visitor attentions.

Now without any more preface garb the code from below and add it to the perfect place where you think it should be.

Table of Contents


1.) It simply displays a list of random posts along with post-excerpts.
2.) Code used here displays 5 random posts and that value can be changed.
3.) You can use it in your WordPress theme anywhere.

<h2>Random Posts</h2>
$args = array( 
'numberposts' => 5, 
'orderby' => 'rand', 
'post_status' => 'publish', 
'offset' => 1
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><p><?php the_excerpt(); ?></p></li>
<?php endforeach; ?>


You can edit it with with your requirement also. You can also add date, time, thumbs, comments, authors and anyhting that a post have. Rest all is done.

Theme Files Editing Warning:

Keep in mind that every code that you will add in your themes files will be removed when you will change the theme. So after changing your theme, you have to follow this article again and you will get everything back same as it is now.

Last Words:

This is what we have and shared in easy steps for newbies so that they can easily know how it works. Stay with us because we are going to share a whole guide step by step about WordPress and make it easy for you. If you liked it then share it and be with us to get next tutorial. If you have any problem then feel free to ask us. We will help you with what we can or have.

Recommended For You:
Follow These SEO Trends For Better Rankings With Increase Organic Traffic

You Like It, Please Share This Recipe With Your Friends Using...

2 Responses to “How To Display Random Posts In WordPress Without A Plugin?”

  1. Gaurav says:

    Thanks for sharing this post about “random posts”without using any plugin or tool. I will use this code in my blog too. WordPress CMS has been very popular blogging platform for every blogger and entrepreneur. It is the most recommended and lovable CMS. WordPress is very easy to operate and total time saving, because of its feature and tools. Since few year WordPress has developed and updated his system to create more use friendly platform. Thanks for this article.

Leave a Reply

Your email address will not be published. Required fields are marked *