This function below creates a list of links of the top commented posts on your WordPress blog. It builds this list based on the posts that have the most comments. Place it in your footer or sidebar item!
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php function listPopularPosts() { global $wpdb; $strBuidler = ''; $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) { $strBuidler .= '<li>'; $strBuidler .= '<a href="' . get_permalink($postId) . '" title="' . $title . '">' . $title . '</a> '; $strBuidler .= '(' . $commentCount . ')'; $strBuidler .= '</li>'; } } return $strBuidler; } ?> |