Display “Most Popular” posts on sidebar.
Advertisements
If you have been blogging since some months/years and your blog has been getting good number of comments, you may have notice that some posts are getting more comments that other posts. This means that some posts are more popular than other posts.
It will be a good idea to display your “Most Popular” posts in the sidebar. This will make your visitors stay longer on your blog and more chances of them subscribing your RSS feed.
Now the “Most Popular” posts can be sorted out based on number of comments or number of views.
Plugins using most views as a criteria are -
- Popular Posts
- WP-PostViews Plus widget
- Recently Popular
- WordPress.com Popular Posts
- Yet Another Most Popular Posts
- KF most read
There is one most popular plugin for this purpose Alex King’s “Popularity Contest”. It uses various factors as criteria to sort out “Most Popular” posts list.
There are other plugins that use number of comments as a criteria for “Most Popular” posts. Here are some -
If you don’t want install any plugin for “Most Popular” posts, then you can use following to display it. Just copy-paste the following code on your sidebar.php file. To change the number of displayed posts, simply change the 5 , highlighted in red to any number you want. Also if you want to change its title, just change ‘Popular Posts’, highlighted in green to anything of your choice.
If you enjoyed this post, make sure you subscribe to my RSS feed!<h2>Popular Posts</h2>
<ul>
<?php $result = $wpdb->get_results(“SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5“);
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<li><a href=”<?php echo get_permalink($postid); ?>” title=”<?php echo $title ?>”><?php echo $title ?></a> {<?php echo $commentcount ?>}</li>
<?php } } ?>
</ul>
