Make WordPress Core

Changeset 2881


Ignore:
Timestamp:
09/15/2005 11:40:04 PM (19 years ago)
Author:
ryan
Message:

get_comments_number() improvements from markjaquith. fixes #1677

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment-functions.php

    r2828 r2881  
    4040}
    4141
    42 function get_comments_number( $comment_id ) {
    43     global $wpdb, $comment_count_cache;
    44     $comment_id = (int) $comment_id;
    45     if (!isset($comment_count_cache[$comment_id]))
    46         $comment_count_cache[$comment_id] =  $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_id' AND comment_approved = '1'");
     42function get_comments_number( $post_id = 0 ) {
     43    global $wpdb, $comment_count_cache, $id;
     44    $post_id = (int) $post_id;
     45
     46    if ( !$post_id )
     47        $post_id = $id;
     48
     49    if ( !isset($comment_count_cache[$post_id]) )
     50        $comment_count_cache[$post_id] =  $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'");
    4751   
    48     return apply_filters('get_comments_number', $comment_count_cache[$comment_id]);
     52    return apply_filters('get_comments_number', $comment_count_cache[$post_id]);
    4953}
    5054
Note: See TracChangeset for help on using the changeset viewer.