Posted by chellman on April 30, 2008 at 9:21pm
It looks to me like theme_comment_wrapper has no way of knowing how many comments there are. Is there a good way to get this information into the comments header?
This is the evil, fragile method I'm using now: counting strings!
function phptemplate_comment_wrapper($content) {
if (!empty($content)) {
preg_match_all ('/<div class="comment-inner/', $content, $matches);
$num_comments = count($matches[0]);
$header = 'Comments ('. format_plural($num_comments, '1', '@count') . ')';
return '<div id="comments"> <h5>'. $header .'</h5>'. $content .'</div>';
} else {
return '';
}
}Please tell me there's a better way.
Comments
I would like to know too.
I would like to know too. Anyone have a suggestion?
If you mean comments per
If you mean "comments per node" use this (drupal 6):
<?phpecho $node->comment_count;
?>
I was asking this about
I was asking this about Drupal 5, but it's good to know this exists in Drupal 6.
I downloaded Drupal 5 and
I downloaded Drupal 5 and check it. $node->comment_count exists. Try it and u ll be happy :)
Change this:
$header = 'Comments ('. format_plural($num_comments, '1', '@count') . ')';to this:
$header = 'Comments ('. format_plural($node->comment_count, '1', '@count') . ')';and erase your preg_match_all function.
Not quite that simple
Thanks for looking at that. I will look into this way of doing. It's not quite as simple as you say, though, because the function where this appears, theme_comment_wrapper, doesn't have access to the $node object. Making $node global might work, although that feels icky.
I used the original solution
I used the original solution proposed as in my site $node and $vars are empty when i use phptemplate_comment_wrapper or zen_comment_wrapper in themplate.php