0

everybody. So I'm creating a blog theme and have put the_excerpt() in content.php

My index.php displays different post excerpts for the different kind of posts-formats. I have content-gallery.php, content-audio.php, etc and in each of them I have the_excerpt() instead of the_content(). If I put the_content() and there is a lot of text before the read-more tag, it breaks the layout, because the design is made for little snippets for each post.

Does that mean that I can't use get_template_part( 'content', get_post_format() ) in single.php, because it will return an excerpt and not the whole content?

In the content.php, I could put:

if( is_singular() ) {
    the_content();
}

Or create subpages of single.php like single-gallery.php.

What is the correct way of arranging the hierarchy when using the_excerpt() in content-{post-type}.php?

  • 2
    This question is impossible to answer without seeing your actual code, and knowing the exact context in which it is used. – Chip Bennett Jul 15 '13 at 15:04
  • @chip-bennett Yeah, you are right. I have added more information to the post. I don't know if it is enough? – Ziik Jul 15 '13 at 16:17
4

the_content() does not grab the PHP file content.php, it simply displays a Post's content. Likewise, the_excerpt() grabs the excerpt of a post.

get_template_part simply finds a file within your theme named whatever you put in, with an optional suffix.

get_template_part( 'content' ); // content.php
get_template_part( 'content', 'my_page' ); // content-my_page.php

in order for make different displays for Gallery, Aside, etc. do this in single.php

get_template_part( 'content', get_post_format() );

It will point to content-gallery.php, content-aside.php, etc. with a fallback of content.php if the file specified is not defined.

Edit: All you need to do here is restructure your content-{post-format}.php files. Inside those, use the_content(), and create excerpt-{post-format}.php files where you can then use the_excerpt().

Then your call in index.php would be get_template_part( 'excerpt', get_post_format() ), where inside your single.php it would be get_template_part( 'content', get_post_format() )

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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