Create Random Posts Section without using Plugins

From how much time are you Blogging? The days going on will bury up your older blog posts. The new visitors coming to your blog will miss those valuable posts. Cool thing to get back the older posts is by displaying random posts in the sidebar. This will sure attract the visitors towards the older posts and you too can get more page-views for you blog. Random Posts can be displayed in two ways.

  1. Using plugins like Random Posts or Advanced Random Post. But everyone doesn’t likes to install plugins for each and every activity, as using plenty of plugins will slow downs the site.
  2. The second one is for coding lovers πŸ™‚ . There is an simple php script which shows the required number of posts in pages/sidebar.

Here is the code, just copy the code and apply it in the sidebar of your theme.

<h2>Random Post</h2>

<?php $posts = get_posts(‘orderby=rand&numberposts=5’); foreach($posts as $post) { ?>
<li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a>
<?php } ?>

In default I have mentioned number of posts to 5, you can change it to your wish. If you have any doubt, please have a look of the snapshot below:

After applying the code you will get the random posts at your blog, you can see the preview of random posts section in my site:

Also Read: Are You Sure to Publish Your Post

BlueHost Offer Sale HostGator Offer Sale
  1. abhi

    You created your own plugin. Really useful code. It is working.

    • NavaPavan

      @abhi, Thanks Abhi πŸ™‚ You can subscribe to our feeds for more useful posts.

  2. Genite

    This is very small an simple code wow this is great code.

  3. strGraphics

    Ohh really superb friend..,

    In fact earlier i searched for plugin regarding this. But its very much useful i will use this in my blog for sure.


  4. Anish K.S

    Its recommended that avoid too much plugins, thanks Pavan Somu.
    .-= Anish K.S´s last blog ..Jagran Solutions Sets Up MICE Division =-.

  5. federal student loan

    It’s posts like this that keep me coming back and checking this site regularly, thanks for the info!

  6. Pubudu Kodikara

    Now i have been searching for the plugin which does this… i think now i can do it in a more easier way πŸ˜€ thanks for the post mate πŸ˜€
    .-= Pubudu Kodikara´s last blog ..Lets Tweet From Your Inbox! =-.

  7. Vinay

    Great way to stay away from Plugins πŸ™‚ and even the loading speed of website will be faster πŸ™‚
    .-= Vinay´s last blog ..Google TV : Search Engine’s New Revolution!! =-.

Leave a Reply

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

CommentLuv badge