We always suggest you to avoid plugins. Many of bloggers use plugins to show popular posts in WordPress. Today we learn how to show Popular posts without any plugin.

How to Add Popular Posts in WordPress Without Plugin

Add this code in your theme where you want the popular posts to be displayed. This code will run a SQL query to get the most commented post.

<ul class="popular_posts">
 <?php $nz = new WP_Query('orderby=comment_count&posts_per_page=5'); 

 while ($nz->have_posts()) : $nz->the_post(); ?>
 <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
 <p>Posted by <strong><?php the_author() ?></strong> with <?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></p></li>
 <?php endwhile; ?>
 </ul>

In the above code you can change number of show post by changing ‘posts_per_page=5‘ in the 2nd row.

Pin It on Pinterest

Shares
Share This