WordPress.org

Ready to get started?Download WordPress

Forums

Only display comment count if post allows comments (2 posts)

  1. pshero
    Member
    Posted 3 years ago #

    Hey gang, I need a little WP PHP help, I've searched for an hour with no luck.

    I need to know how you'd write the following statement for my comment count in the post meta line under the title of each post, currently I'm using:

    Comments: <a href="/#comments"><?php comments_number('no responses','one response','% responses'); ?></a>

    But I'd like to exclude the comment count altogether if the post doesn't allow comments, so basically I need an if statement that says "if the post allows comments then display the above phrase, else don't"

    Thanks a million...

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    http://codex.wordpress.org/Function_Reference/comments_open

    try:

    <?php if( comments_open( $post->ID ) ) { ?>
    Comments: <a href="/#comments"><?php comments_number('no responses','one response','% responses'); ?></a>
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.