How to use Post Formats in WordPress 3.1

WordPress 3.1 has seen the introduction of Post Formats. They provide the ability to target posts within templates using get_post_format() and through css using the extra classes wordpress now adds automatically to posts. This will save on creating extra categories or tags just for targeting and styling these types of content.

So how does it work…

Functions.php
Add this to the functions.php file in your theme. You only need to list the formats you wish to use.

1
2
// This theme uses post formats<br/>
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link','image', 'quote', 'status', 'video', 'audio', 'chat' ));



You will then see a list of radio buttons in your edit post right hand column.

Styling
Once a type is selected you can style using the following class added to your post on listing pages

and using the following class added to your tag on single pages.

Templates
Within your templates you can target posts by format using the following code

1
2
3
 if ( has_post_format( 'image' )) {
  echo 'this is an image format';
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>