What, Whys, and How to’s of Post Formats in WordPress 3.1
Post formats is one of the exciting features that are coming in WordPress 3.1. But most beginners have no idea what are post formats, why should they matter to you, and how you can take advantage of this awesome feature. Well after going through the alpha version of WordPress 3.1, we have decided to explain the what, whys, and how to’s of Post formats feature that is coming within WordPress 3.1.
What are Post Formats?
Post Formats are meta information that can be used by themes to customize presentation of a post. Ok, now in plain english post format are a method of styling a specific post. By using this feature, you can specify the display “format” of a specific post. This feature expands the micro-blogging aspect of WordPress because now you can have videos, links, images, audios, quotes, statuses, etc. all in one place, and the best part is that they will be styled accordingly.
Examples of Usage
Lets take a look at Digging into WordPress official blog. They have two type of post styles on the homepage. One is a complete post which is displaying an excerpt, just like any other blog. But what is interesting is that they have a specific style of a post that are external links to other blog posts that they find useful for their readers.
Blogging is all about sharing resources, and often it is the case where blogger wants to just link to an external resource because he/she finds it useful for their readers. The main problem they face is that they have to make a new post in order to just tell the readers to go to another site. This creates confusion for the end-user because they do not know what type of post it is. Often, the user has to click on the full view of the post just to find out that the author wants them to view an external link. Even though there are tricks like this one, that lets you link to external links from post titles, this post format issue will fix it all. Theme designers can style the “link formats” to be displayed in a different way like Jeff Starr has for Digging into WordPress.
The power of this feature is too much to describe. Because now you can write short status posts like you would on twitter, and have it styled differently without doing too much of work. If you found a quote that you like, you can share it and have it stand out with one click. The bottom line is that the “post formats” feature will make WordPress a more complete blogging platform.
Why you want to use Post Formats?
Post formats replaces the need to use categories to accomplish the similar styling features. Until now, developers hacked WordPress categories to accomplish this effect which ends up creating a lot of clutter and confusion for new bloggers. Using post formats will not only cut down clutter in terms of categories, it will make your blog portable between themes that support those formats.
It will also make your blog more user-friendly for your readers because your user will know exactly what type of post they are viewing. Furthermore, it will make your blog more lively because you will have different style of posts on your blog page. Right now, most blog post display looks very dull because all posts look alike. The post formats will fill a much needed void within the WordPress powered sites.
How to Add and Use Post formats in WordPress 3.1
Just like post thumbnails, Menus, Custom Backgrounds, and Custom headers, the post formats will also be a theme activated feature. What this means is that this feature will only be available if your theme is compatible.
Warning: You must have a fair understanding HTML, CSS, and the functions of the WordPress loop to follow this tutorial.
In order to activate “post formats” in WordPress 3.1, you will need to open your theme’s functions.php file and paste the following code:
add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
Note: aside, and gallery are not the only available post formats. The available list of post formats are:
- aside – Typically styled without a title. Similar to a Facebook status update.
- chat – A chat transcript.
- gallery – A gallery of images.
- link – A link to another site.
- image – A single image.
- quote – A quotation.
- status – A short status update, usually limited to 140 characters. Similar to a Twitter status update.
- video – A single video.
For the full list of post formats, refer to WordPress Codex.
Once you have added this code, you will see a new field in your post write panel in the right hand column where you see publish.
Upon writing the post, you can change the format and hit publish. This will allow you to display your post in a pre-styled format.
But wait, we have not yet specified these pre-styled post formats anywhere in our theme. So right now, even if you select the format in your WordPress post panel, it will not make a difference because your theme does not know how to display it. For this, we will need to edit our post loop.
We are going to be utilizing the conditional tag: has_post_format()
if ( has_post_format( 'aside' )) { // code to display the aside format post here } else if (has_post_format('gallery')) { // stuff to display the gallery format post here } else if (has_post_format('link')) { // stuff to display the link format post here }else { // code to display the normal format post here }
Now what are you waiting for? Start preparing yourself for this awesome feature. We can only imagine WordPress being used more and more as a micro-blogging platform with new themes that will come out utilizing this feature.
Additional Readings:
WordPress Codex Post Formats
Post types and formats and taxonomies, Oh my!
Post Formats vs. Custom Post Types