Simple way to make popular post without plugin

0 7518

Simple way to make popular post without plugins. In the script that I created way is as follows ...

Write the following code in functions.php

if( !function_exists('ktz_popcon')) {
function ktz_popcon() {
$pc = new WP_Query(array('post_type'=> 'post', 'showposts' => 9, 'post_status' => 'publish', 'ignore_sticky_posts' => 1,'orderby' => 'comment_count'));
$popcon = '';
while ($pc->have_posts()) : $pc->the_post();
global $post;
$permalink = get_permalink();
$title = get_the_title();
$popcon .= '<li><a href="' . $permalink . '" title="' . $title . '">' . $title . '</a></li>';
return $popcon;

Now open the template you want pasted popular post. Now paste the following code:

<ul><?php echo ktz_popcon(); ?></ul>

Easy and simple you can use that code in anywhere. If any bugs or problem just comment..

banner 468x60
Category: WordpressTags:
Hello world! My name gian, im from blogging from indonesian. Im interest with webdesign, php coding and wordpress. Why i choose wordpress? Because its simple and easy to use for my blog. And thanks to read my article.