WordPress.org

Forums

How do you check if a post has comments ? (4 posts)

  1. Matt B.
    Member
    Posted 6 years ago #

    Hi guys,

    Is there a way to check if a post/page has comments already ? I would like to include my javascript only on posts/pages who have comments already.

    Thanks,

  2. Plucko
    Member
    Posted 6 years ago #

    Yeah I'm wondering that too. Does anyone know how to do this?

  3. lkanter
    Member
    Posted 5 years ago #

    If you're in the Loop, you can use use the built-in function, get_comments_number()

    so,

    <?php
    if (get_comments_number()==0) {
        // post has no comments
    } else {
        // post has comments
    }
    ?>
  4. jessor
    Member
    Posted 5 years ago #

    thanks =)

Topic Closed

This topic has been closed to new replies.

About this Topic