Grabbing the most commented posts in WordPress usually ends in one of two ways: writing a direct database query that bypasses caching and strains your server, or installing a heavy add-on that drags down your load times.
Let’s look at the clean, code-first approach that actually respects your site’s performance, plus a realistic alternative if you refuse to touch PHP.
Method 1: The Code-First Approach (Keep It Light)
Years ago, developers would hit the database directly to tally up comments. Don’t do that. It ignores object caching entirely and puts unnecessary stress on your server.
The proper route is leveraging WP_Query.
Drop this snippet into your theme files—usually sidebar.php or a custom page template—to pull the top five discussions.
<div class="most-commented-posts">
<ul>
<?php
// Query the top 5 most commented posts
$args = array(
'orderby' => 'comment_count',
'order' => 'DESC',
'posts_per_page' => 5,
'post_status' => 'publish',
// 'cat' => 3, // Uncomment and change ID to restrict to a specific category
);
$popular_query = new WP_Query( $args );
if ( $popular_query->have_posts() ) :
while ( $popular_query->have_posts() ) : $popular_query->the_post();
$comment_count = get_comments_number();
// Only show posts that actually have comments
if ( $comment_count > 0 ) : ?>
<li>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
<span class="comment-count">(<?php echo $comment_count; ?> comments)</span>
</li>
<?php endif;
endwhile;
wp_reset_postdata(); // Always reset post data after a custom query
else : ?>
<li>No commented posts yet.</li>
<?php endif; ?>
</ul>
</div>
Method 2: Stop Breaking Your Layouts
If you have a narrow sidebar, a 15-word post title is going to shatter your layout. Don’t try to chop the title by character count. That almost always ends up slicing an emoji in half or breaking a special character.
Use the native WordPress wp_trim_words() function instead. Swap out the standard title call in the loop above for this six-word limit:
<?php echo wp_trim_words( get_the_title(), 6, '...' ); ?>
Method 3: Pulling in Featured Images
Text lists are easy to ignore. If you want people to actually click, pull in the featured image.
Here is the adjusted loop using has_post_thumbnail(). It keeps things neat and organized without requiring a third-party page builder to render the layout.
<div class="most-commented-with-images">
<?php
$popular_query = new WP_Query( array( 'orderby' => 'comment_count', 'posts_per_page' => 5 ) );
if ( $popular_query->have_posts() ) :
while ( $popular_query->have_posts() ) : $popular_query->the_post();
if ( get_comments_number() > 0 ) : ?>
<div class="popular-post-item">
<?php if ( has_post_thumbnail() ) : ?>
<div class="post-thumb">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( array( 60, 60 ) ); // 60x60 pixel image ?>
</a>
</div>
<?php endif; ?>
<div class="post-details">
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<span class="comment-count"><?php echo get_comments_number(); ?> Comments</span>
</div>
</div>
<?php endif;
endwhile;
wp_reset_postdata();
endif; ?>
</div>
Method 4: The Plugin Route (If You Really Have To)
If the thought of editing your theme files makes you sweat, or if you absolutely demand advanced metrics, grab the WordPress Popular Posts plugin.
Why use an add-on when you have the code? Because the PHP snippets above pull all-time comment counts. If you have a ten-year-old site, a viral post from 2016 is going to dominate that list forever.
This plugin tracks actual visitor views and lets you filter by timeframe—like the most commented or viewed posts in the last 7 or 30 days.
It comes with a built-in block, saving you the headache of writing custom sorting logic from scratch.