July 25th, 2009 | Categories: Wordpress | Tags: , , , , ,

Hi everybody, you can show your most commented popular posts wtihout any plugin. It’s a simple code. Easy useable and appliable. We will edit siderbar.php or single.php. Where you want to show popular posts, you can edit any file. If you are ready, Lets begin…

Here is the code;

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

If you want to make a Popular Post Widget, you can use this code on sidebar.php or if you want to show this after post, you have to add this code after loop in single.php.

If you change the number “5” you can change Popular Posts Number :)

That’s All! Have a nice day.


  1. February 17th, 2010 (4 weeks ago) at 19:05
    Reply | Quote | #1

    Good tutorial… thanks ..

  2. February 19th, 2010 (3 weeks ago) at 11:20
    Reply | Quote | #2

    You’re Welcome!

1 trackbacks

  1. Muestra tus anuncios sólo en Post antiguos - colorate Pingback | 2010/02/17 (4 weeks ago)