• I’m trying to add a tiny suffix to article titles, which would show the visitors how many comments a given article has. But, if the the comment section is closed, it gives me a big and nasty ‘comments closed’ remark. I don’t want that.

    So I’ve tried my hand at PHP to disable this ‘comments closed’ remark. Here’s my code:

    <?php if ( comments_open() ) { comments_popup_link( '0', '1', '%' ); } else { &nbsp; } ?>

    Except: it doesn’t work. It just refuses to load half the page if I enter this code. I’m really not sure how this php code is faulty, so I would be grateful if someone could point out to me what I did wrong.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Not sure if you found your answer but try:

    if ( comments_open() ) :
      echo '<p>';
      comments_popup_link( '0', '1', '%', 'comments-link', '');
      echo '</p>';
    endif;

    enable DEBUG to see any error messages;
    https://codex.www.ads-software.com/Debugging_in_WordPress

    right now, you are inserting html (that is the ?) directly into php.

    you don’t need the else part if it is not doing anything;

    try to simplify the code to:

    <?php if ( comments_open() ) { comments_popup_link( '0', '1', '%' ); } ?>

    or correctly close and open the php tags like:

    <?php if ( comments_open() ) { comments_popup_link( '0', '1', '%' ); } else { ?> ? <?php } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP code glitching on comments_open()’ is closed to new replies.