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.

It seems to me that twentyelven opens standard single posts using the file content-single.php yet when I try the same code and files they open for me in content.php

here's the code I have in index.php

<?php get_template_part( 'content', get_post_format() ); ?>

... then I have two files content.php and content-single.php

Standard posts are opening up in content.php not content-single.php

How can I fix this?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

There's actually nothing to fix.

In Twenty Eleven, this is used in index.php:

<?php get_template_part( 'content', get_post_format() ); ?>

...and this is used in single.php:

<?php get_template_part( 'content', 'single' ); ?>

The design intent here is that all posts, regardless of post format, will display the same in single-post view, but that posts with defined post formats will have a custom display in archive indexes.

If you have a different design intent - e.g. you want to use the post-format custom display in the single-post view, simply change the call in single.php from this:

<?php get_template_part( 'content', 'single' ); ?>

...to this:

<?php get_template_part( 'content', get_post_format() ); ?>

Likewise, if you want to call content-single.php from within index.php, you'd need to change the call the other way around, perhaps like so:

if ( get_post_format() ) {
    get_template_part( 'content', get_post_format() );
} else {
    get_template_part( 'content', 'single' );
}

Another approach:

$postformat = ( get_post_format() ? get_post_format() : 'single' );
get_template_part( 'content', $postformat );

Either should result in the same thing.

share|improve this answer
    
I missed the fact that there was a single.php file ... when I saw the content-single.php file I jumped to the conclusion that get_post_format() defaulted to 'standard'; ( which would have seemed more intuitive to me; but I'm sure I'll see the logic when I get to use it more) .... but by the looks of it it defaults to false, which is why I think I'll need your suggestion of if ( get_post_format() ) ... etc ... to do what I was trying to do. Thanks –  byronyasgur Jul 26 '12 at 19:03

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.