• I wanted to use a

    php if (there are comments) { show this and that }

    syntax so I looked up comments.php and found this

    ?php if ($comments) : ?

    1. So I used this in archives.php (which is my substitue for index.php) within The Loop as

    php if ($comments) { blabla }

    but it returns false on every post, including those which have comments.

    2. I then tried pulling out the results from comments_popup_links

    php if (comments_popup_link(‘0′,’1′,’1′)==’1’) { echo(‘there are comments’); } ?

    and it didn’t work. (the plugin just echoes the stuff on screen and doesn’t pass on variables)

    So how can this be done? Help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • $comments is not a global variable, but is created through the comments_template() function (just for the…comments template). So it won’t be available otherwise.

    Try using get_comments_number(), which is the underlying function of comments_number():

    if(get_comments_number($post->ID))

    Thread Starter yokima

    (@yokima)

    It works! Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to use the “existence of comments” in an IF statement’ is closed to new replies.