WP-MostCommentedPosts – hack
-
Hi, I’d like to adapt the WP-MostCommentedPosts plugin (https://ja.rafi.pl/2006/05/01/wp-most-commented-posts/)
This plugin counts the number of comments per post and displays the top ranking posts.I’d like to adapt that so I can grab the most commented posts per any category ID specified.
The plugin code:
function get_mostcommented($limit = 10) {
global $wpdb, $post;
$mostcommenteds = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_date, COUNT($wpdb->comments.comment_post_ID) AS 'comment_total' FROM $wpdb->posts LEFT JOIN $wpdb->comments ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND post_date_gmt < '".gmdate("Y-m-d H:i:s")."' AND post_status = 'publish' AND post_password = '' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_total DESC LIMIT $limit");
foreach ($mostcommenteds as $post) {
$post_title = htmlspecialchars(stripslashes($post->post_title));
$comment_total = (int) $post->comment_total;
echo "<li>» <a href=\"".get_permalink()."\">$post_title</a> - $comment_total </li>";
}
}Can anyone help?
Thanks.
- The topic ‘WP-MostCommentedPosts – hack’ is closed to new replies.