Dukeo » WordPress » Popular Posts: How To List Them by Comments Count

Popular Posts: How To List Them by Comments Count

Steven WordPress

For your fresh blog readers, it can be pretty tricky to find the most valuable posts in your archives. This is why a very interesting thing to do on your WordPress blog is to share a list of your most popular posts.

There are many plugin-based solutions to get a list of popular posts, however, you might want to keep your blog as clean as possible by using a minimum number of plugins.

The idea is to get a list of your popular posts by comment count, simply paste the following code where you want it to be displayed:

<?php $pop = $wpdb->get_results("SELECT id, post_title, comment_count FROM {$wpdb->prefix}posts WHERE post_type='post' ORDER BY comment_count DESC LIMIT 10"); ?>
<ul>
<?php foreach($pop as $post) : ?>
<li> <?php echo $post->post_title; ?> </li>
<?php endforeach; ?>
</ul>

If you enjoyed this article,
Get email updates

Join for Free »