How to Get Most Commented Posts With Thumbnail on Your Blog!

thumbnailIn order to help your visitors finding your best content, bloggers often display their most commented posts on their blog’s sidebar. Through this tip, I’ll show you how you can get most commented posts along with thumbnail.

Its very simple to get most commented posts with thumbnail on your blog, nothing difficult.Simply paste this code anywhere in your theme files, where you’d like the most commented posts to be displayed. Don’t forget to replace the custom field name by yours on line 5:

<?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 the_title(); ?>" />
	<?php } else { ?>
	<img src="http://an-alternative-image.jpg" alt="" />
	<?php } ?>
	<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php endwhile; ?>

Thanks to Alex Denning for this nice trick!