Get most commented posts with thumbnails

In order to help your visitors finding your best content, blogger often display their most commented posts on their blog’s sidebar. Here is the code that you can get most commented posts along with their related thumbnail.

Simply paste this code anywhere in your theme files, where you’d like the most commented posts to be displayed.

<?php $popular = new WP_Query('orderby=comment_count &posts_per_page=5'); ?>
<?php while ($popular->have_posts()) : $popular->the_post(); ?>
<?php $justanimage = get_post_meta($post->ID, 'Image', true);
	if ($justanimage)
        { ?>
<img src="<?php echo get_post_meta($post->ID, "Image", true); ?>"alt="" />
<?php }
else
{ ?>
<img src="http://an-alternative-image.jpg" alt="" />
<?php } ?>
<a href="">
<?php the_title(); ?>
<?php endwhile; ?>

Source: http://techmandu.com/2010/07/23/get-most-commented-posts-with-thumbnails/

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.