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.

What is it about?

This Q shall become a collection of code snippets about post-formats and their use cases.

What to add?

Please add snippets/functions/classes/project-links about...

  • Pulling & transforming specific data from the post for presentation. For e.g. "link"
  • Improvements for the admin UI. For e.g. filtering the list view, adding meta boxes & custom fields to new posts.

How to add

Please add a h3-heading first. It should contain the post-format it's about or "admin UI detail/list", so the thread is easily readable.

Please then add a short description and then your snippet. Commented code is highly appreciated.

Thank you!

share|improve this question

closed as too broad by toscho Dec 20 '13 at 19:46

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

Using get_template_part() with Post Formats

This is a really handy little snippet to use when you want to change the output format for each post format.

if ( have_posts() ) :
     while ( have_posts() ) : the_post();

        // Standard is the default template for posts with no post format
        // As the formats doesn't contain  it, but the function returns false
        // We add it as fallback
        get_template_part( 'format', ! get_post_format() ? 'standard' : get_post_format() );

        endwhile;
endif;

In your theme folder create a file for each post format, like so:

  • format-standard.php (this is the default template)
  • format-video.php (this file would be used for posts with video formats)
  • format-audio.php (this is used for audio formats)
  • etc, etc

This snippet would be used in your single.php and/or blog archive templates to control the output format of each post format. Doing it like this really helps to keep your template files clean and easy to read.

This is described more in-depth in the Post Formats tutorial on WP Roots.com

share|improve this answer
    
I hope you don't mind the edit. It's just a little shorter and nicer :) –  kaiser Feb 6 '12 at 19:01

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