Support » Themes and Templates » have_comments() HELP

  • So I’m experiencing something really ridiculous… within my comments.php loop I am logically calling:

    <?php if ( have_comments() ) : ?>

    The problem is, it isn’t working at all… it never thinks there’s any comments. I’m automatically dumped into the else part of the statement…

    FYI: I do not have a function.php


Viewing 3 replies - 1 through 3 (of 3 total)
  • I’ve used <?php if(have_comments()) : ?> dozens of times without any problem. So perhaps the problem is elsewhere in your code.

    I ran into this problem as well. It’s not that it never works, it’s that it will always return false until after comments_template() is called. I’m not sure why this doesn’t use the same method as comments_number(), but it doesn’t and it sucks. What you should be able to use instead is get_comments_number() which returns the number of comments.

    I know this was posted a month ago, but hopefully it will save someone like me some time.

    The $comments variable is boolean. It will either be true or false. Within your post loop it will have one of the two values. That’s purely an indicator of whether or not comments are allowed.

    The other functions such as have_comments() and wp_list_comments() don’t contain any data until comments_template() is processed.

    comments_template() makes the appropriate calls to retrieve the comments data, but it also includes the comments.php file.

    Don’t do:

      include(TEMPLATEPATH . '/comments.php');

    Instead do:


    Hope that helps,


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘have_comments() HELP’ is closed to new replies.