By john.kenney on
I'd like to display the comment count on my pages.
Preferably to shown up on the same line as the 'Comments' headline that starts my comments sections. Example page: http://www.aboutcallingcards.com/pingo-review. Positioning isn't really the issue though - getting it to print is.
I have a slightly customized thing my tech guy added to my template.php file as shown below:
function taoist_comment_wrapper($content, $node, $comment_count) {
if (!$content || $node->type == 'forum') {
return '<div id="comments">'. $content .'</div>';
}
else {
return '<div id="comments"><h2 class="comments">'. t('Comments'). '</h2>'. $content .'</div>';
}
}
I think what I need is simply something like this adding the correct variable name and printing it in a div or p. But I'm clueless about variable names and how to print them, so my lame attempt below didn't work and other variants blew up the pages.
function taoist_comment_wrapper($content, $node, $comment_count) {
if (!$content || $node->type == 'forum') {
return '<div id="comments">'. $content .'</div>';
}
else {
return '<div id="comments"><h2 class="comments">'. t('Comments'). '</h2>'. '<p id="comment-count">' . t($comment_count) .'</p>'. $content .'</div>';
}
}
Can anyone tell me the correct way to do this? This is for D6.
Thank you!
Comments
not sure
I'm not sure why your attempt isn't working.
Can't you do something like
Number of comments: <?php print $comment_count ?>in your node.tpl.php?got it
ah, poked around a bit more and found out that I wasn't calling variable quite right. was missing something.
the correct formulation is as follows:
now need to tweak positioning, but at least it is printing in roughly the right spot.
another tweak
Turns out that wasn't quite right either - worked, but was generating php errors in the background because of calling 1 too many variables.
Here is illustrative code for creating custom Comments section header (i.e., changing the comment_wrapper function), including comments count:
This code needs to go into your template.php file. Change 'YourTheme' to your actual theme name.
The 'if' part of this is not strictly necessary, but demonstrates how you could have different comment header / wrapper for different node types. If you are smarter than me, you could also remove the if - else and just apply this to all content types.
You obviously can change the text, classes, HTML elements, etc. in any way that suits your purposes.