WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On my single.php and index.php I'm including the comment entry routine with this code...

<?php if(get_option('allow_comments_posts')){comments_template();} ?>

However, when the specific post being viewed in single.php has "Allow Comments" unchecked, I don't want the comment template to appear.

I was under the impression that the comments_template() routine automatically managed this, but apparently I need to wrap it or pass a paramater?

share|improve this question
up vote 2 down vote accepted

As far as I remember main purpose of comments_template() is to load template and specific logic should be handled inside that template.

Snippet from Twenty Ten comments.php:

if ( ! comments_open() ) :
    <p class="nocomments"><?php _e( 'Comments are closed.', 'twentyten' ); ?></p>
<?php endif; // end ! comments_open() ?>
share|improve this answer
thanks for pointing me there. Apparently, something is amiss with my $post variable or scope. Even though the current post I'm looking at has "allow comments" unchecked, comments_open() is returning true. Any ideas? – Scott B Jan 21 '11 at 19:55
Ah, I think I see what's happening. I have a "Related Articles" listing just before the comments_template() call. The $post->ID is getting reset to the last post in the link list for those articles. Should I redeclare $post inside comments.php? If so, $post = ? – Scott B Jan 21 '11 at 20:04
@Scott B try wp_reset_query() after your related section – Rarst Jan 21 '11 at 20:06
BINGO! That did it. Thanks Rarst. As always, you're right on the money :) – Scott B Jan 21 '11 at 20:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.