Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am playing around with template hierarchy. I have uploaded stock 2012 theme and deleted page.php and single.php. I found that when I visit a blog post and click the the post reply link to leave a comment, the comment form doesn't show. So I copied comments_template() function out of single.php and pasted it into content.php inside the is_single conditional that looks like this

    <?php if ( is_single() ) : ?>
        <h1 class="entry-title"><?php the_title(); ?></h1>
        <?php else : ?>
        <h1 class="entry-title">
            <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
        </h1>
 //added the comments template here
 comments_template( '', true);
        <?php endif; // is_single() ?>

from that, I would expect the comments template to show but it does not. It did however show up when I added the is_single conditional to the index.php loop

Why would it not work in the

 get_template_part( 'content', get_post_format());
share|improve this question
    
the comments_template() code should be in the 'if' section. –  Michael Feb 1 '13 at 8:44
add comment

1 Answer

up vote 0 down vote accepted

Looks like you're trying to display comments for a single post that has comments disabled.

You should find if ( comments_open() ) statement just one line below.

Paste your code there and it will work just fine:

            <?php if ( comments_open() ) : ?>
                <div class="comments-link">
                    <?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
                </div><!-- .comments-link -->
                <?php comments_template( '', true); ?>
            <?php endif; // comments_open() ?>

Also, I can't find PHP starting & ending tag in your example, but I suppose it's just a typo? :)

Cheers, I hope it helps.

share|improve this answer
add comment

Your Answer

 
discard

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.