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.
- 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.
- 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>
</li><ul>
<?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>
</li>
<?php } ?>
</li></ul>
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
You created your own plugin. Really useful code. It is working.
@abhi, Thanks Abhi π You can subscribe to our feeds for more useful posts.
Hi,
This is very small an simple code wow this is great code.
@Genite, yes, it is a tiny code which helps a lot.
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.
Thankssss.
@strGraphics, Nice to hear that it really helped you π
Its recommended that avoid too much plugins, thanks Pavan Somu.
.-= Anish K.S´s last blog ..Jagran Solutions Sets Up MICE Division =-.
Itβs posts like this that keep me coming back and checking this site regularly, thanks for the info!
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! =-.
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!! =-.
@Vinay, Yup! you are right bro