1
votes
<?php comments_number();?>

This WordPress function counts the number of comments on a post; when there are no comments it returns the text "NO comment". This causes problems in my layout, so I would like it to display 0 zero instead. How do I do that? As far as I know I have to make a filter, but I don’t know which hook to use.

Also, how do we know this is the right hook? Some tips on how to work this out would be even more beneficial so that I can create a filter on my own next time.

2

2 Answers

5
votes

comments_number

You can set zero like:

comments_number('0', '1', '%');

Documentation: http://codex.wordpress.org/Function_Reference/comments_number

get_comments_number

Or you can use get_comments_number that returns value of the total number of comments as only numeric value

$num = get_comments_number();

if ( $num == 0) {
   // something to do
}

Documentation: http://codex.wordpress.org/Template_Tags/get_comments_number

0
votes

As per http://codex.wordpress.org/Function_Reference/comments_number you can do

comments_number('0 Comments', '1 Comment', '% Comments');