G-D00XZP85S3 How to Display Most Commented Posts in WordPress (2 Ways) - KangMus Official
Skip to content Skip to sidebar Skip to footer

How to Display Most Commented Posts in WordPress (2 Ways)

Do you want to display your most commented posts in WordPress?

Highlighting your most commented posts helps your visitors find your best content, increase pageviews, and boost website engagement.

In this article, we’ll show you how to display the most commented posts in WordPress, step by step.

How to display most commented posts in WordPress (2 ways)

Why Display the Most Commented Posts in WordPress?

Your most commented posts have very high levels of user engagement. By displaying your popular posts, you encourage new readers to join the discussion and spend more time on your WordPress website, while boosting your social proof.

When your visitors stay on your site longer, this gives you a chance to convince them to read another post, join your email list, or make a purchase.

Plus, when new visitors leave a comment, they become part of the community. This can help you build trust with your readers over the long term.

That being said, let’s take a look at how to simply display your most commented posts in WordPress using 2 methods.

Method 1: Display Most Commented Posts With a Plugin in WordPress

There are many different WordPress popular posts plugins that you can use to display your popular articles, but the simplest to use is MonsterInsights.

It’s the best analytics solution for WordPress used by over 3 million websites. With this plugin, you can easily display your most commented posts anywhere on your website.

First thing you need to do is install, activate, and set up the plugin. For more details, see our beginner’s guide on how to install Google Analytics in WordPress.

Note: there is a free version of MonsterInsights, but we’re using the pro version for this tutorial since it includes the popular posts feature.

Upon activation, navigate to Insights » Popular Posts and then click the ‘Popular Posts Widget’ menu item.

MonsterInsights popular posts

On this screen, you will control the appearance of your most commented posts.

Simply select the ‘Theme’ you want to use for your most commented posts. The theme operates similar to your WordPress theme and will control the overall design of the most commented posts widget.

There are a ton of other customization options on this screen as well.

For example, in the ‘Theme Preview’ meta box, you can display your most commented posts in a ‘Wide’ format below your content, or ‘Narrow’ format to the right of your content.

MonsterInsights display options

After that, you have more options for customizing the design.

For example, you can change the size and color of the title, icon, and background.

Customize how most commented posts display

MonsterInsights will automatically save any changes you make to your most commented posts display settings.

Once you’re finished customizing the appearance of your commented posts, it’s time to display your popular posts by comments.

In the ‘Sort By’ meta box, simply select the ‘Comments’ button.

Sort by most commented

MonsterInsights will automatically display your most commented posts.

You have a few different options for adding your popular posts to WordPress. You can choose manual or automatic placement.

If you choose ‘Automatic’ placement, then the plugin will add your most commented WordPress posts directly after the last paragraph of your blog posts.

Automatic popular posts placement option

The other option is to display your most commented posts manually. If you select the ‘Manual’ option, then you can add the popular posts widget with a Gutenberg block or a shortcode.

To do this, open up a page or post where you want to display your most commented posts.

Then, click the ‘+’ icon and select the ‘Popular Posts’ block.

Select MonsterInsights popular posts block

This will automatically add your most commented posts to your page.

Make sure you click ‘Update’ or ‘Publish’ to make your changes live. Now when your users visit the page, they will see your most commented posts displayed.

Update or publish page changes

Display Most Commented Posts in Your WordPress Sidebar

If you want to display your most commented posts in your WordPress sidebar, then go to Appearance » Widgets.

After that, find the ‘Popular Posts — MonsterInsights’ widget and drag it to your sidebar widget area.

MonsterInsights popular posts widget to sidebar

Next, you can give your widget a title, choose the number of posts to display, select the theme, change colors, and more.

The customization options are similar to the widget customization settings above.

Once you’re done making changes click ’Save’, and your popular posts with the most comments will be live on your WordPress blog.

Most commented posts sidebar example

Method 2: Display Most Commented Posts Without a Plugin in WordPress

The second method involves adding code to your WordPress files. If you haven’t done this before, then check out our beginner’s guide to pasting snippets from the web into WordPress.

However, there are some downsides to using this method. First, it involves adding code to WordPress, so it’s not very beginner friendly.

Second, the code isn’t as optimized for performance as the MonterInsights plugin, so it will increase the server load, and it can slow down your website.

That being said, let’s take a look at how you can display most commented posts in WordPress without a plugin.

You’ll want to add the following code to your functions.php file, in a site-specific plugin, or by using a code snippets plugin.

function wpb_most_commented_posts() { 
// start output buffering
ob_start();
?>
<ul class="most-commented">
<?php 
// Run WP_Query
// change posts_per_page value to limit the number of posts
$query = new WP_Query('orderby=comment_count&posts_per_page=10'); 
 
//begin loop
while ($query->have_posts()) : $query->the_post(); ?>
 
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> <span class="wpb-comment-count"><?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></span></li>
<?php endwhile; 
// end loop
?>
</ul>
<?php
 
// Turn off output buffering
 $output = ob_get_clean(); 
 
//Return output 
return $output; 
}
// Create shortcode
add_shortcode('wpb_most_commented', 'wpb_most_commented_posts'); 
 
//Enable shortcode execution in text widgets
add_filter('widget_text', 'do_shortcode');

The code above will run a database query and fetch 10 posts ordered by the highest comment count. Then, it uses output buffering to create a shortcode you can use to display the posts.

The last line of the code creates a shortcode that you can use in your posts, pages, and widget areas.

To display your popular posts, all you need to do is add the following shortcode to your WordPress site.

[wpb_most_commented]

For more details, see our beginner’s guide on how to add a shortcode in WordPress.

If you want to add thumbnails next to your post titles, then add the following line of code right after <li> tag in the code above.

<?php the_post_thumbnail(array(40,40)); ?>

This code will define the custom size for the post thumbnail images. You can adjust the size to meet your needs.

Once you’ve done that, you can style how your most commented posts will display.

To do this you can modify the .most-commented and .wpb-comment-count CSS classes in your WordPress theme’s stylesheet.

For more details, see our guide on how to easily add custom CSS to your WordPress site.

You can use the following CSS to get started:

.most-commented li { 
border-bottom:1px solid #eee; 
padding-bottom:3px; 
} 
.most-commented li :after { 
clear:both;
} 
.most-commented img { 
padding:3px;
margin:3px;
float:left;
}
.wpb_comment_count a, .wpb_comment_count a:active, .wpb_comment_count a:visited, .wpb_comment_count a:hover { 
color:#FFF;
}

We hoped this article helped you display the most commented posts in WordPress. You may also want to see our ultimate WordPress SEO guide to get more traffic, and our list of the best WordPress plugins for businesses.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Display Most Commented Posts in WordPress (2 Ways) appeared first on WPBeginner.



source https://www.wpbeginner.com/plugins/how-to-display-most-commented-posts-in-your-wordpress-sidebar/

Post a Comment for "How to Display Most Commented Posts in WordPress (2 Ways)"