
One of my readers, Chris Berry, recently asked in the forum how he can display the number of comments for each posts. While some themes do it by default, most of them don’t display it at all. Here’s a recipe to solve Chris problem.

One of my readers, Chris Berry, recently asked in the forum how he can display the number of comments for each posts. While some themes do it by default, most of them don’t display it at all. Here’s a recipe to solve Chris problem.
To achieve this recipe, simply open your index.php file and paste the following code within the loop:
<?php comments_number('No comments yet','1 comment','% comments')?>
Even better, this simple line of code have a link to jump directly to the comments:
<a href="<?php the_permalink() ?>#comments"><?php comments_number('No comments yet','1 comment','% comments')?></a>
7 Responses
Hey,
Instead of the last one, try . Much cleaner and it accepts the same parameters as comments_number.
I have also been using this little code to showoff comments on some of my most popular posts. Thanks for this breakfast recipe.
Good for themes that don’t have this feature ^_^
I don’t understand where in the html I should insert that code. Can someone please help?
Thanks!
Got to implementing this at my blog. Few issues:
1. permalink is excessive I think, link to anchor is enough inside post.
but!
2. if there are no comments yet #comments anchor doesn’t exist and link fails. comments_popup_link function handles this by changing anchor to #respond but it doesn’t work inside single post.
No promises on code quality but that’s what I ended up with:
<a href="<?php if (0==get_comments_number()) echo '#respond'; else echo '#comments'; ?>" title="Comments"><?php comments_number('Reply', '1 Comment', '% Comments'); ?></a>
Trackbacks: