Simple way to make popular post without plugin

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

[prettify]

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>’;
endwhile;
return $popcon;
}
}

[/prettify]

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

[prettify]

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

[/prettify]

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