How To Create Popular Post without Plugin


Today tricks is how to create popular post without any plugin. We need to run little bit query using some code and place this code on whatever you want to put on. Example we can put this code on the sidebar.php or footer.php

To Create Popular Post without any plugin, please write down this code on your sidebar.php or footer.php

<h2>Popular Posts</h2>
<ul>
< ?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<li><a href="php echo get_permalink($postid); ?>" title="< ?php echo $title ?>">< ?php echo $title ?></a> {< ?php echo $commentcount ?>}</li>
< ?php } } ?></ul>

Please note, this popular post based how many comment. More comment it’s mean more popular post.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s