your code works as is for me.. as in ‘no comments’ is displayed for posts with no comments.
check if its inside loop, and i would use an ID like ‘mycommentcount’ or something instead of ‘comments’..
Hmm, I tried changing the id to “comments-label” and that didn’t change anything. Then I tried switching out my call to comments_number with the one for twentyfourteen, and still saw no change. It works for 1 or multiple comments, but displays nothing for 0 comments.
I checked the comment-template.php and that hasn’t been changed.
It seems like there must be a setting somewhere I’m missing? But I don’t know where else to look.
checked on a different post? this looks like a simple typo or cascading issue man.. or just dump the code and try using this:
<?php
printf( _n( 'One thought on “%2$s”', '%1$s thoughts on “%2$s”', get_comments_number(), 'twentyfourteen' ),
number_format_i18n( get_comments_number() ), get_the_title() );
?>
^ took it from twentyfourteen theme.. ofcourse make necessary changes..
Yeah I checked it on a different post and tried using the code from twentyfourteen without changing it at all to test. Still getting the same results. It works for 1 or multiple, but doesn’t work for 0 posts.
I got this to work. I’ll follow-up once I figure out the details. Thanks for your help, Shadez. I appreciate it!
So, the comments_number function was inside an if statement that contained all the rules for comments, and one of the rules must have been causing this issue.
I couldn’t figure out which one, but moving the comments title outside of the if statement fixed the issue.
(@mpare1987)
12 years, 5 months ago
I am using the comments_number function to display a count of the amount of comments beneath my posts. It is working fine for one and multiple comments, but displays nothing when there are 0 comments. Here is my function:
<h3 id=”comments”><?php comments_number(‘No comments’, ‘<span>1</span> Comment’, ‘<span>%</span> Comments’); ?></h3>
When there are 0 comments, the h3 with id “comments” doesn’t get pulled into the page at all. I’ve looked everywhere, but can’t seem to find a similar issue. The only plugin I have installed is jetpack (I’m using the contact form).
I’m also developing this off of the bones theme: http://themble.com/bones/
Appreciate any help. Thanks!
http://ww.wp.xz.cn/plugins/comments/