wordpress hacks

Display Top Comments in WordPress

by Franklin Bishop on June 9, 2009

If you are wanting to display the top comments in WordPress then use the code below. You can change the limit in the coding if you prefer to do so. WordPress should allow you to do this without interfering with any of your other code.

<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 10");
foreach ($result as $topten) {
$postid = $topten->ID;
$title = $topten->post_title;
$commentcount = $topten->comment_count;
if ($commentcount != 0) { ?>
<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"><?php echo $title ?></a></li>
<?php } } ?>

If this code does not allow you to display top comments then it must not be compatible with your WordPress theme. Every Blog I have used with WordPress has not had a problem with the top comments coding. Hopefully you will not either.

{ 1 comment }

Ben July 11, 2009 at 7:56 am

Thanks been looking for this code everywhere.
Goes nicely in my footer :)

Comments on this entry are closed.

Previous post:

Next post: