On Asides

As you may have noticed on this page or in your aggregator my normal entries are now interspersed with smaller link and commentary entries represented in an unordered list. These fall in chronological order with my other entries and are real posts with permalinks, comments, categories, trackbacks, and pingbacks. I have been wanting to do this for a long time and there was a flood of entries when I first got this working. I fully expect to post in this category with a much higher frequency than my normal posts. I come across things all the time that I want to link so badly but I just don’t have the time to write an entry about. Now every interesting tidbit I come across is just a click of a favelet away from my readers. It’s liberating.

The format of a weblog dictates its writing. There is no getting around this. Ever since my redesign I’ve had these big important titles that—as a writer—are intimidating. Everything I write has to be worthy of its 32-point Dante banner. This was a deliberate to force myself to put more thought and effort into my entries and it has worked; some of my best writing has been since the redesign. It has been stifling as well. To express what I want to express these days I need something more dynamic.

This type of linklog is nothing new. I first saw it at Kottke and since have enjoyed it at Charles Gagalac’s site. Charles was the first person I know of to do it in WordPress. This inline style fits my requirements very well, the biggest being that I wanted to use my existing post taxonomy so a second weblog would have been inconvienent. I also get the benefit of a combined RSS feed and combined update pinging. More than all of that though, I don’t want to limit myself to one type of post in a new weblog, or in this one. I already have plans to use this feature to not only highlight interesting links, but comments I make on other sites, upcoming gigs I have, photolog updates, and various activities and writing I now have spread out over a half-dozen blogs. It’s a perfect application for WordPress‘ multiple sub-categories feature. Technically, the whole thing was very easy to implement.

First I made a new category all of these posts would be a part of, it was late and I couldn’t think of anything too clever, so I went with “Asides.” This may have been subconciously inspired by Movable Blog. So I created the category in WordPress, and it had an ID of 33. Next it was simply a matter of telling my template that if a post was in the Asides category to lay it out a little differently. I wrote a quick function, in_category() that does this with no additional DB queries that is now in the WordPress CVS and will be in the 1.2 release. The function takes a single argument, a category ID, and it returns true if the current post is in that category. Here’s what I have in my post loop:

So basically what this is saying is that if the post is in category #33 and we’re not on a permalink page to format it using that code, otherwise do our normal thing. We have a simple unordered list with a uniquely ID’d list item. (The ID is a throwback to about two years ago when I had a heavily hacked version of b2 with monthly archives. Can’t let those permalinks break.) I get the post content directly because I didn’t want to mess with the normal filters (like autop) applied to the_content(). I run it through texturize to keep everything pretty. Then I have a simple comment link, and finally a link that only I see that allows me to easily edit any entry. This worked great, but you can see that I have a separate unordered list for each entry, which isn’t what I want; I want all consectutive aside entries to be part of a single list. This gets tricky because you have to start the list when the current entry is an aside but the newer entry and stop it when the next entry is not an aside. Tricky tricky, and I don’t want to think what would happen if someone decided to reorder my content. I had only allocated myself ten minutes for this entire project and I was at minute number eight, so it came time for ugly code:

I swear that’s the actual code in my template. Put it somewhere around the top of the template, it really doesn’t matter where. It’s a hack, but it’s been working great. Simon says it is “ugly as sin,” and that’s what I thought when I wrote it. Since then, however, it has grown on me a bit. It’s like the supermodel who goes out every day dressed to the nines relaxing at home in a bathrobe, slippers, and no makeup. I keep the pretty code elsewhere, here at home I’m a little more casual. Perhaps when I have a little free time I’ll put in the more complicated logic I described above but if it ain’t broke…

Thank you for sharing the information, I had “asides” running on my site for some time now using this tip. I tried to impliment your method (because I does not mess with autop), but it creates a weird problem with links. s are added where they don’t belong in links and abbreviations i.e. <a href="http://secure.sixapart.com/">?

I’ve been using Charles’s variant for a few weeks now, and it’s working great. Except of course for the fact that entries are being sorted chronologically and not categorically and then chronologically. I swear, I need to teach myself PHP so I can do these kinds of things myself and not continually apply pressure to you WP guys 😉

I’d really like to get this code up and running on my blog but I’m having trouble. I’m struggling to know where in the loop to place the code and how to terminate it so that I don’t get a parse error at this line<?php endforeach; else: ?>

Ever since my redesign I’ve had these big important titles that””as a writer””are intimidating.

Oh my god, I wrote almost the same exact sentence yesterday in my post announcing my redesign. The problem with the way my old site used to look was each post felt so BIG. Hopefully, my new design will make it easier on the eyes when I post a bunch of one or two liners.

I’ve been thinking about how to integrate the “link and run” part of my weblog for a while. Nothing has worked as well as I would like.

But I have to say that the way you are doing it has taught me a clear lesson in how not to do it. It’s very annoying to have to sift through such a length of links to see the real content. I much prefer either a separate log (for frequent posting) or these links consolidated into a daily/weekly/irregular posting (for less frequent posting).

Does that function in_category also scan the children categories? I need to exclude posts from a certain category and all it’s children, because those posts are being used for something other than my “blog”.

Here is my situation. I have a site where there are 5 bloggers, each with their own category. I have them all as the same level, but don’t want them to be able to edit each others posts. Is there a quick index.php hack to make this happen? I’ve posted in the wp support forum, but havent gotten an answer. Thanks.

Is there any reason why you would not want to use a simple flag to signal the opening and closing of a group of asides?
Granted this isn’t the prettiest code either, but it definitely beats having to parse all outputs searching for regex matches.
Something along the line of:
if (! $opened_list)
{
Â Â Â Â $opened_list = true;
Â Â Â Â echo "

I’m having problems with this lovely hack. I get all sorts of parse errors (“unexpected $ in /…/wordpress/index.php on line 184 – that’s towards the end of my index.php (for a readable version: http://www.matthiasheil.de/wordpress/index.phps – Could it be I’m missing out on sth important here?

Hi Matt, not sure if you’re still checking your comments for this post but I was wondering if there was a way to adapt this code to handle more than one category. I’d like to have a number of different layouts for a number of different categories (about five or so). I’ve tried monkeying around with the code a bit but I can’t work it out. It seems like a relatively simple prospect to me, but I could be wrong since I’m a PHP n00b. Thanks for this great tutorial regardless. I do have asides working just fine on my site.

Everything I write has to be worthy of its 32-point Dante banner. This was a deliberate to force myself to put more thought and effort into my entries and it has worked; some of my best writing has been since the redesign.

I took your idea for Asides and pull in my Twitter RSS (@smjdesign) via Alex King’s TwitterTools. Twitter makes a very good way to add asides to your blog. You might consider it. Semantically–for my use, they are the same.

I have it working on a personal website. I doubt that I will be adding it to my professional websites anytime soon due to the “off-topic-ness.” Make sure though if you bring them into your blog and subsequent RSS feed that your entire homepage isn’t full of tweets/asides!