If you’re willing enclose the whole thing in the link, you could just change:
<?php comments_number('no comments', 'one comment', '% comments');?>
to:
<?php comments_number('There are no comments on this post.', 'There is one comment on this post.', 'There are % comments on this post.');?>
Assuming you thought of that and found it inadequate, how about get_comments_number? It’s not documented in the Codex, but the code of the comments_number function (which can be found here) calls it and it seems to be returning an integer.
Thread Starter
Jeff
(@jmf)
Awesome! Thanks, ikiru — I was trying to avoid enclosing the whole thing in a link, but get_comments_number was exactly what I was looking for!
Can you please post a guide to getting this to work. I am not so good with php but this is exactly what I am looking for.
I get the gist of what is happening I just dont know where to put the code.
(@jmf)
17 years, 10 months ago
I’m working on a theme where I’d like the comment string at the end of a post to appear as a phrase, with only the number of comments linked… the equivalent of:
There are no comments on this post.
I also need the text to switch “There are” and “There is” depending on the number of comments, of course.
So here’s what I’ve been working with:
My problem is, I can’t find anything to switch off of — is there a variable or function I can use to grab the number of comments on a post? Or am I going about this completely wrong way.