From ef29f0ba5f897fd8e227483fa8a6678b58d2bd32 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 15 Sep 2005 23:40:04 +0000 Subject: [PATCH] get_comments_number() improvements from markjaquith. fixes #1677 git-svn-id: http://svn.automattic.com/wordpress/trunk@2881 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-functions.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/wp-includes/comment-functions.php b/wp-includes/comment-functions.php index c62ed97f00..ee940f99aa 100644 --- a/wp-includes/comment-functions.php +++ b/wp-includes/comment-functions.php @@ -39,13 +39,17 @@ function clean_url( $url ) { return $url; } -function get_comments_number( $comment_id ) { - global $wpdb, $comment_count_cache; - $comment_id = (int) $comment_id; - if (!isset($comment_count_cache[$comment_id])) - $comment_count_cache[$comment_id] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_id' AND comment_approved = '1'"); +function get_comments_number( $post_id = 0 ) { + global $wpdb, $comment_count_cache, $id; + $post_id = (int) $post_id; + + if ( !$post_id ) + $post_id = $id; + + if ( !isset($comment_count_cache[$post_id]) ) + $comment_count_cache[$post_id] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'"); - return apply_filters('get_comments_number', $comment_count_cache[$comment_id]); + return apply_filters('get_comments_number', $comment_count_cache[$post_id]); } function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $number = '' ) {