Using WordPress Post Formats as a Taxonomy

Filed in Web DevelopmentTags: Post Formats, Themes, WordPress

One of the great new features in the soon-to-be-released WordPress 3.1 is Post Formats. This feature enables posts to be classified as one of the following "types": standard (default), aside, audio, chat, gallery, link, quotestatus, or video. As described in the WordPress Codex:

A Post Format is a piece of meta information that can be used by a theme to customize its presentation of a post. The Post Formats feature provides a standardized list of formats that are available to all themes that support the feature... In short, with a theme that supports Post Formats, a blogger can change how each post looks by choosing a Post Format from a radio-button list.

Clearly, the most obvious use of Post Formats will be to customize the layout or style of a post based on the selected Post Format type. While this use will be incredibly beneficial, it does not fully describe the power or functionality of the Post Formats feature.

To give just one example, the Post Formats feature includes its own taxonomy (similar to Categories or Tags). Having their own taxonomy means that posts can be displayed by Post Format type.  Compare:

Category taxonomy:
mysite.com/category/foo-bar
Tag taxonomy:
mysite.com/tag/foo-bar
Post Format taxonomy:
mysite.com/type/foo-bar

Consider the potential of this taxonomy. Want to add podcasting to your site? Assign all of your podcast posts the audio Post Format type, and your podcasting section becomes mysite.com/type/audio. Want to add a photo gallery section to your site? Assign your gallery posts to the gallery Post Format type. Photoblogging? Use the image Post Format type. Videoblogging? Use the video Post Format type.

Implementing Post Format Taxonomy in Themes

Making use of the Post Format taxonomy in Themes is incredibly easy, thanks to a few functions:

  • get_post_format() - return the Post Format slug, e.g. 'aside'.
  • get_post_format_string( $post-format ) - return the Post Format string, e.g. 'Aside'.
  • get_post_format_link( $post-format ) - return the URL to the Post Format archive page, e.g. mysite.com/type/aside

Breadcrumb Navigation

For example, I have added the Post Format taxonomy to the breadcrumb navigation in my Oenology Theme:

Post Format Breadcrumb Navigation

Post Format Breadcrumb Navigation

This breadcrumb is accomplished simply by using:

get_post_format_string( get_post_format() )

(Note: the output is a string, to which I appended a 's' to the end, because I think "Post Format: Images" is more intuitive than "Post Format: Image" in this context.)

Taxonomy Archive Links

As another example, I have added links to the Post Format taxonomy archive:

Post Format Link

Post Format Link

This link is accomplished using the following code:

'<a href="' . get_post_format_link( get_post_format() ) . '">' . get_post_format_string( get_post_format() ) . '</a>'

Taxonomy Sidebar Widget

How about adding a Widget that outputs a list of Post Format types, to complement the Category and Tag Widgets? Here's a rough proof-of-concept:

Post Formats Sidebar Widget

Post Formats Sidebar Widget

The code for this is a bit more convoluted, but here are the important bits:

<ul class="leftcolcatlist">
<?php
$postformatrssimg = "/images/rss.png";
$postformatrssurl = get_template_directory_uri() . $postformatrssimg;
$postformatterms = get_terms( 'post_format' );
foreach( $postformatterms as $term ) {
$termslug = substr( $term->slug, 12 );
$termname = $term->name;
$termlink = get_post_format_link( $termslug );
$termcount = $term->count;
$postformatlist = '<li><a title="Subscribe to the '. $termname .' news feed" href="' . home_url() . '/type/' . $termslug .'/feed/"><img src="'.$postformatrssurl.'" alt="feed" /></a><a href="'. $termlink .'">' . $termname . '</a> (' . $termcount . ')</li>';
echo $postformatlist;
}
?>
</ul>

What else? Well,  what about adding Post Format taxonomy to a menu?

Just remember: with Post Formats, think outside the box of Post layout and style, and consider what else you can do with this great new feature!

I've added a proof-of-concept example of a Post Format sidebar Widget, complete with taxonomy archive link, feed link, and count

Feedback

Comments (Comments are closed)

17 Responses to “Using WordPress Post Formats as a Taxonomy”
  1. chip_bennett says:

    Using WordPress Post Formats as a Taxonomy – http://www.chipbennett.net/2011/01/11/us… #wordpress

  2. chip_bennett says:

    @dougal @itsananderson a minor contribution of my own to the Post Formats implementation conversation: http://www.chipbennett.net/2011/01/11/us

  3. Would it be a good idea to implement this in “generic” themes? If you do this you’re basically turning Post Formats into a third taxonomy with a slightly different user interface, but the whole point of Post Formats was to avoid the generic “Taxonomies as display parameters” paradigm. It seems like treating Post Formats as just another taxonomy might confuse users (just like Categories used to).

    That being said, I can see some cases where it might be neat. For example, if you wanted to have a site where you posted videos, blog posts, and Twitter like updates (asides), you could do a little query magic and have 3 top level pages that each displayed one format. Once again, though, you could probably just as easily do that with categories, and this would be a more specialized (not very generic) theme.

    In general, my preference would be to use post formats when multiple formats need to be displayed on one page, but stick with taxonomies for organization (i.e. “show only this kind of post”).

  4. Great write up for an idea of how Post-Formats can be used … adds some food for thought for a new (client) theme I’ve been considering.

  5. A few really great ideas here. Another good idea might be to list all formats in the sidebar as a navigation structure. You could even go as far as to use the post format as a node in a custom faceted navigation structure. Really excited about this feature!

  6. Chip Bennett says:

    Michael:

    Great idea. I’ve added a proof-of-concept sidebar Widget to the Post.

    Thanks!

  7. Chip Bennett says:

    CAPTCHA test comment

  8. Craig Hartel says:

    Thanks for this article, Chip. It helped me understand the concept a lot better and now I can appreciate the new functionality in 3.1.

  9. DavidM says:

    It’s so nice to see all that functionality get added into WordPress. Being the tweaker that I am, I can already see myself needing some alternate or additional post format types. :)