How to show most commented posts with thumbnail in WordPress

Here is another handy WordPress snippet to show most commented posts with thumbnail. Add below code to your template and it will display most commented posts with thumbnail.

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

Related posts:

HTML5 page structure

HTML5 offers more powerful structure comparing to older versions of Html. There are many new …

Partner with Us

We are providing an exclusive partnership offer to individuals and companies who are interested in setting up their own web design & development company. For more information about how to partner with us, please contact us