Post Formats, Tumblog, and Content Separation by Jeffrey Pearce


Jeffrey Pearce is a developer who focuses on PHP and jQuery. He has a background of web application development and WordPress customization and is currently working with WooThemes to deliver new features to their platform.

Post Formats, Tumblog, and Content Separation

I remember a time when WordPress had a pretty simple content separation system of Categories and Tags, and life was simple but not really flexible when it came to extending your WordPress blog to be a rocking CMS. Then came the joy of playing with Custom Post Types and Custom Taxonomies and they really made me smile. And now hot on their heels, is the newly introduced Post Formats.

Inspired by the micro-blogging arena of Tumblr, post formats aims to meet the growing need by WordPress developers to provide a alternative to this service. But, even before post formats, WooThemes has been providing Tumblog (tumblr style) WordPress themes with microblogging facilities to the WordPress community. Here’s how I built it, initially using Categories, then Custom Taxonomies, and now using Post Formats!

Theme Options, Categories, and Custom Taxonomies

We needed to be able to separate the different Tumblog posts so that we could change the output on the frontend depending on what type (image, article, etc) the post was, and the best way initially to do this was to use categories. So we created a setup for the categories in our theme options panel:

Once the user had chosen which category they wanted, the code to figure out the frontend side of things went like this in the loop, to simply check if the post is in a specific category and then call a custom output function:

1
2
3
4
5
<?php 
if ( in_category( get_option( 'woo_articles_category' ) ) ) {
    woo_tumblog_articles($id, $count);
}
?>

Then came WordPress 3.0 and the widespread adoption of custom post types and taxonomies. After chatting with Matt Mullenweg, we decided to modify the Tumblog functionality to use a custom taxonomy called ‘tumblog’ instead of categories. This affected the above code, by eliminating the need for the category selection, but added some complexity to the frontend code by using get_the_term_list() and get_term_by() in order to figure out which Tumblog type the post was. But on the plus side, it allowed for better separation of content from regular posts.

The Dashboard Widget

When categories were being used to separate the posts into the different Tumblogs, the dashboard widget post creation was easy to code.

1
2
3
4
<?php
$tumbl_note['post_category'] = $categories;
$post_id = wp_insert_post($tumbl_note);
?>

But when we switched over to using a custom taxonomy, the complexity increased to:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
$post_id = wp_insert_post($tumbl_note);
//update posts taxonomies
$taxonomy_data = $data['tax_input'];
if ( !empty($taxonomy_data) ) {
    foreach ( $taxonomy_data as $taxonomy => $tags ) {
        $taxonomy_obj = get_taxonomy($taxonomy);
        if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
            $tags = array_filter($tags);
        if ( current_user_can($taxonomy_obj->cap->assign_terms) )
            array_push($tags, $tumblog_items['articles']);
    }
} else {
    $tags[0] = $tumblog_items['articles'];
}
wp_set_post_terms( $post_id, $tags, 'tumblog' );
?>

Again, even thought this was an increase in complexity, it benefitted the users by allowing improved content separation.

Enter Post Formats

WordPress 3.1 is coming out soon with the new post formats functionality. This was conceived to allow a facility for micro-blogging like Tumblr from within WordPress, by setting a post format when creating a post. This is very similar to the current WooTumblog plugin but with a couple of minor changes. I decided to test post formats and see if it would be worthwhile switching the WooTumblog plugin over from the current custom taxonomy method to post formats.

On the frontend, it ended up simplifying the code back to something similar to the original categories way of doing things:

1
2
3
4
5
<?php 
if ( has_post_format( 'aside', $post_id  ) ) ) {
    woo_tumblog_articles($id, $count);
}
?>

While also simplifying the dashboard widget post creation code:

1
2
3
4
<?php
$post_id = wp_insert_post($tumbl_note);
set_post_format( $post_id, 'aside' );
?>

So overall I’m impressed with it’s ease of implementation into existing themes and plugins, providing low complexity and high functionality. If you want to try out post formats for yourself, get a copy of the WordPress 3.1 beta release, and try these new functions:

* add_theme_support(‘post-formats’, array(‘aside’,‘video’)) – not a new function, but this will add post formats support to your theme for aside and video
* has_post_format(‘video’, $post_id) – checks if a post has the video format
* set_post_format($post_id, ‘video’) – sets a posts format to video
* get_post_format($post_id) – gets the format for a post

Express App

Taking this even further is the Express for WordPress iPhone App. This allows you to post simply from your iPhone in Tumblog style! It doesn’t currently support post formats, but this has been discussed with the development team for a future release. Check it out here – http://express-app.com – or in the App Store.

Hot off the press – here’s a beta preview of the WooTumblog plugin using Post Formats – Merry Christmas! http://www.jeffikus.com/download/5/

* Note: this version of the plugin does not support posting from the Express for WordPress iPhone App at this time. This may be introduced in the near future. Also, you must use WordPress 3.1 beta as this plugin will not work on 3.0, and due to this being a beta plugin, support is not provided, although feedback is most welcome :-)

Further Reading: My slides from WordCamp Spain on Post Formats, Tumblog, and Express for WordPress – http://www.slideshare.net/jeffikus/wordcamp-spain-2010-presentation

Comments (1)

Participate