Many times you want to show the popular posts in your wordpress theme and you use popular post wordpress plugin or widget for showing the popular posts in your wordpress theme. As much possible you need to avoid the wordpress plugins for minimal code.
most popular posts wordpress without plugin
With very easy steps you can fetch the most popular posts from your wordpress. Most common trick or technique is on comments base you can fetch the popular posts.
You just need to open your functions.php file from wordpress posts and put following code in file.
// Get Most Popular Posts in theme function popular_posts_by_comments( $posts = 5) { $popular = new WP_Query('orderby=comment_count&posts_per_page='.$posts); while ($popular->have_posts()) : $popular->the_post(); ?> <li> <div> <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a> <span><?php comments_popup_link('0 Comment', '1 Comment', '% Comments', 'comments-link', ''); ?></span> </div> <!--end .info--> <div></div> </li> <?php endwhile; }
This is very easy code to fetch you wordpress popular posts. Here I am fetching only 5 popular posts from wordpress. You can fetch the multiple popular posts by changing the $post variable value.
In wordpress theme sidebar or footer section if you want to show the popular post then just use following code.
popular_posts_by_comments();
where you want to show the popular posts.
Great tutorial you visit also http://techsloution4u.com/wordpress/create-a-popular-post-widget-without-plugin.html