? flat_comments_reply_count.patch ? sites/all/modules/devel ? sites/all/modules/devel-7.x-1.x-dev.tar.gz ? sites/default/files ? sites/default/settings.php Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.749 diff -u -p -r1.749 comment.module --- modules/comment/comment.module 4 Aug 2009 06:53:48 -0000 1.749 +++ modules/comment/comment.module 7 Aug 2009 14:00:23 -0000 @@ -1509,14 +1509,19 @@ function comment_load($cid) { function comment_num_replies($pid) { $cache = &drupal_static(__FUNCTION__, array()); - if (!isset($cache[$pid])) { - $cache[$pid] = db_query('SELECT COUNT(cid) FROM {comment} WHERE pid = :pid AND status = :status', array( - ':pid' => $pid, - ':status' => COMMENT_PUBLISHED, - ))->fetchField(); + // Only calculate the replies when threaded comments are enabled. + $mode = variable_get('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED); + if (COMMENT_MODE_THREADED_EXPANDED == $mode || COMMENT_MODE_THREADED_COLLAPSED == $mode) { + if (!isset($cache[$pid])) { + $cache[$pid] = db_query('SELECT COUNT(cid) FROM {comment} WHERE pid = :pid AND status = :status', array( + ':pid' => $pid, + ':status' => COMMENT_PUBLISHED)) + ->fetchField(); + } + return $cache[$pid]; } - - return $cache[$pid]; + // Otherwise the number of replies to this comment will be 0. + else return 0; } /**