Popular posts are a good way to show off your blog content which is highly visited by the users. In this way you are encouraging visitors of your blog to view the content which has been voted by visitors in a way to be good. It’s a good way to let users visit the other posts of the blog. I am going to use the previously posted code which counts for every visit which any visitor makes to your posts. Those visits counter will be used to arrange the posts in the descending order of the views. In this way I am able to show the most viewed posts or you can say that “Popular WordPress Posts using visits counter without a plugin“.
Getting the most popular WordPress post Loop using the Visits Counter:
After you are able to count for the every visit done to the posts. Grab this Code of WordPress post loop below and paste it anywhere in you theme to show the most popular posts.
<h3>Popular Stuff:</h3> <?php $popularpost = new WP_Query( array( 'posts_per_page' => 4, 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); while ( $popularpost->have_posts() ) : $popularpost->the_post();?> <li> <a href="<?php the_permalink() ?>" title="<?php the_title();?>"><h1><?php the_title();?></h1></a> </li> <?php endwhile; ?> <?php wp_reset_query(); ?
This is it! This is the loop code for WordPress posts. If you need any help understanding it then you should know the general knowledge about the WordPress loop. I am going to post about the WordPress loop soon to help the visitors of this blog understand that how they can create simple loops with summary, thumbnail and title support. In the above loop just title has been added and it’s much easy for advanced users to add the images and summary. Well, leaving this part to you. Or wait for the next post for a better understanding of loops. In the above code ‘posts_per_page => 4’ , the 4 shows the number of the posts to be shown in the loop. You can increase it as per your needs. That was it, the Simple Popular WordPress posts without plugin. Happy Blogging 🙂