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>

Comments

There are 1 comments to this post.

  1. johnNo Gravatar

    January 9th, 2010 at 5:34 pm

    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.

Leave a Comment