Tag: Post Formats

  • Using WordPress Post Formats as a Taxonomy

    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