WordPress.org

Ready to get started?Download WordPress

Forums

have_comments() HELP (4 posts)

  1. dColumbus
    Member
    Posted 5 years ago #

    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

    Help?

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    I've used <?php if(have_comments()) : ?> dozens of times without any problem. So perhaps the problem is elsewhere in your code.

  3. donut2d
    Member
    Posted 5 years ago #

    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.

  4. daneharrigan
    Member
    Posted 5 years ago #

    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:

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

    Instead do:

    if($comments)
      comments_template();

    Hope that helps,

    -Dane

Topic Closed

This topic has been closed to new replies.

About this Topic