• Resolved mpare1987

    (@mpare1987)


    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/

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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’..

    Thread Starter mpare1987

    (@mpare1987)

    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 &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', get_comments_number(), 'twentyfourteen' ),
    				number_format_i18n( get_comments_number() ), get_the_title() );
    		?>

    ^ took it from twentyfourteen theme.. ofcourse make necessary changes..

    Thread Starter mpare1987

    (@mpare1987)

    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.

    Thread Starter mpare1987

    (@mpare1987)

    I got this to work. I’ll follow-up once I figure out the details. Thanks for your help, Shadez. I appreciate it!

    Thread Starter mpare1987

    (@mpare1987)

    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.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘comments_number $zero value not displaying’ is closed to new replies.