Post Formats – More Creative Ways For A Theme


First day of our Advent Calendar we show tiny code snippets and brief informations for the Post Formats from WordPress version 3.1.

Some theme authors wanted more defined formats – they wanted the feature “post formats”. This new functionality will be available in WordPress 3.1 and displays an additional meta-information. The Codex for this functionality is available already, and now it’s up to the theme authors to use this new feature.

To use this function, you have to activate it with the Theme. This is controlled, similar to other theme features since version 3.0, over a function. The following syntax gives some of the possible post formats and these can then be used directly on the article, as the following screenshot shows.

add_theme_support( 'post-formats', array( 'aside', 'audio', 'image', 'video' ) );

Just put the code into your functions.php of your Themes.

As possible keys are the following values available.

  • default
  • aside
  • chat
  • gallery
  • link
  • image
  • quote
  • status
  • video
  • audio

Like in thumblr you can design the according article. Via the defined values you can use this across themes. The format will be output with the function body_class() for instant, which creates a class, which you can access via CSS. An exmaple for the value Aside of the post format.

<body class="single single-post postid-52 single-format-aside">

Alternatively there are conditional tags and functions to get to the assigned type:

 echo get_post_format();

As so often depends the creativity and usage on the developer. The biggest benefit is probably that defined values exist and as a theme author you can respond to these formats and as a developer you don’t have to create a new meta box.

Update: The UI received an update, see Andrew’s comment:

WordPress Post formats


Posted

in

by

Comments

10 responses to “Post Formats – More Creative Ways For A Theme”

  1. Konstantin Avatar

    I was kind of sceptical, whether you could keep up with the quality of last year’s posts, but you hit it off impressively!
    Looking forward to the upcoming posts!

  2. Frank Avatar

    @Konstantin: yes, you are right, nowadays it’s hard to write great quality content, especially if it will be every day; But I hope we can meet the expectations. Thanks for your compliment.

  3. Andreas Ostheimer Avatar

    Post formats look good. Kind of overlapping with custom posts (for me) but still very useful.
    Got your RSS feed and look forward to more stuff like this 🙂

  4. Alex Avatar

    Are you sure about ‘audio’? Andrew Nacin didn’t wrote about it. http://wpdevel.wordpress.com/2010/11/11/list-of-post-formats/ and Codex don’t have it

  5. Sören Wrede Avatar
    Sören Wrede

    @Alex There is an Audio Post Format in the Codex http://codex.wordpress.org/Post_Formats

  6. Frank Avatar

    @Alex: sure, i have the list in the post from the code of the current beta version.
    @Sören: thanks for reply!

  7. Galen Gidman Avatar

    This is one way to do it, but you could also just use the WooTumblog plugin. That’s what I use for my site and I couldn’t be happier.

  8. Andrew Nacin Avatar

    @Alex: Thanks, I’ve edited my original wpdevel post. We added audio after that.

    @Galen: The point of the core post formats feature is to offer a standardized set of formats that other themes can then use. When you switch your theme, you won’t lose your format. I’ve spoken (and maybe had a beer or two with) the wonderful guys over at WooThemes, and WooTumblog will utilize post formats. They’ll likely continue to use their own UI instead of the core UI — and that’s fine. It’s just a baseline.

    @Andreas: If you’re unable to draw a clear line between formats and custom post types, then you’re likely misunderstanding one of them. Check out this post by one of the lead developers, Mark Jaquith: http://markjaquith.wordpress.com/2010/11/12/post-formats-vs-custom-post-types/

    @Frank: Your screenshot is already stale. We re-did the UI yesterday. 🙂

  9. Michael Avatar

    Article updated with a screenshot from the last trunk, see Andrew’s comment!