A few weeks back I was struggling with the thought of moving jeremyjaymes.com back to WordPress from Tumblr. While I love the Tumblr platform, I wasn’t quite sure if it was the best solution for what I’d like to do with the site moving forward. With the release of 3.1 looming I realized that I could find the flexibility I needed and utilize “post formats” to replicate some of the tumblr functionality I’d be leaving behind.
Decision made, I jumped into the latest nightly build and got cracking. To get the transition underway I would only need to scratch the surface of what’s possible with post formats but I thought sharing what I did might be helpful to others.
First off I needed to add theme support and register my post formats.
// Add post formats
add_theme_support( 'post-formats', array( 'aside', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video', 'audio' ) );
The above code snippet got dropped into my functions.php. Since I also decided to jump into html5 support in this transition I started with the Toolbox theme by Automattic so the above code was actually added to the function
Once that was done I was ready to start utilizing post formats in my template files. I knew that one of the post formats I was sure to use was that registered above called “links”. I wanted these particular posts to function a lot like Tumblr link posts in that the title of the post became the link to the off-site resource rather than a permalink to the actual post.
The next thing I need to do was open up loop.php (see Toolbox theme, loop.php outputs the loop). The standard entry title for this theme is formatted something like this:
<h2 class="entry-title"> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'toolbox' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
What I added was this:
<?php if( has_post_format('link') ) : ?>
<h3 class="entry-title link"><span class="permalink">∞</span> <a href="<?php echo get_post_meta($post->ID, 'link', true); ?>"><?php the_title(); ?></a></h3>
<?php else : ?>
<h2 class="entry-title"><span class="permalink">→</span> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'toolbox' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php endif; ?>
if( has_post_format('link') ) Checks to see if the post has a post format attached to it, if it has the post format “link” it will use the formatting I’ve designated. You’ll also notice that the actual link is generate through the use of a custom field. So on the post admin end I enter a custom field key of “link” and value equal to the url of the actual link which then wraps the post title and creates the link to the offsite resource. (I also have to designate this particular posts format as a link, see below.)
One other rather nice thing to note is that the post_class now contains a new class .format-link which would allow you to target link posts specifically via css. (If you view the source you’ll also notice format-standard, format-quote and so on.)
That’s it, I’m now able to continue posting in a manner similar to that of my previous Tumblr site while using WordPress for various other reasons. I’ve done a few other things with it which you’ll likely be able to pick out, but for the purpose of this article I’ve kept it short and just touched on the basics rather than go into everything I’ve done. You can see it in action on http://jeremyjaymes.com.
Good news, I’ve also just upgraded to the stable 3.1 release and everything seems to be in good functioning order.