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!


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() );


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

  • 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.