WordPress Popular Post

If you want to display most commented post or most popular post on your blog, you can display that using following code.

WordPress Popular Post or Most Commented Post without a Plugin

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

One Comment

  1. johnNo Gravatar
    Jan 09, 2010

    Nice article dude. I was looking for a plugin to display popular posts. But after reading your post i will use your code on my site.


Trackbacks and Pings

Leave a Reply