I use the wp-CaTT plugin for a simple Technorati hook. All it does is add Technorati links straight off the WordPress categories I choose for each article. I like it because it is simple, focused, and fast. I don’t have to do anything extra — always a bonus, I’m very lazy — to get it to work, and it doesn’t slow down my website either (generally, DreamHost does that just fine all by itself). Other plugins I looked at got all complicated with specialty tags where I’d have to remember not only the syntax, but to do it at all while scribbling my notes down. Or, they had so many (admittedly very impressive) bells and whistles that I simply wasn’t utilizing all of them which always seems a waste. Or worse of all, they slowed the site down.
However, in my mad theme-a-thon of yesterday and in my subsequent tweaking of each theme to standardize them a little bit and so on, I noticed this plugin really didn’t handle different theme’s varying separators. When I print out the categories for each post, I do so via a call like this:
<?php the_category('<br />') ?>
What this does is it prints out the list of category links (linked to my own WP’s database of categorized posts). The parameter tells it how to separate each category, in the above case with br’s, so in that example, all the categories will be on their separate lines (this is from the Barthelme theme). There are all kinds of possibilities: Chocolate Bar uses vertical bars as separators, and DR’s default theme uses commas.
The wp-CaTT plugin, however, is set up so that when I drop it in and use it, I need to edit its php file to set a variable to the same value used in the call to the_category.
Obviously when I started using multiple themes, that became a problem. So I went poking about in the plugin’s code, and found this:
// 1. SET THE Delimiter TO THE CHARACTER YOU'RE USING TO SEPARATE MULTIPLE CATEGORIES APPLIED TO THE SAME POST.
// FOR EXAMPLE, IF YOUR INDEX.PHP FILE CONTAINS the_category(', ') YOUR Delimiter IS ", ".
$Delimiter=", ";
which I replaced with (after tinkering with several other ideas):
if (preg_match("/,/", $url))
$Delimiter = ", ";
else if (preg_match("/<br ?\/>/", $url))
$Delimiter = "<br />";
else if (preg_match("/ \| /", $url))
$Delimiter = " | ";
else
$Delimiter = ", ";
There’s probably a better way to gracefully handle it if none of the matches work. I thought of defaulting to a simple space, but the problem is the $url variable is basically a list of href’s so there’s plenty of spaces, and such a default if it got used would result in a mess on my screen. I suppose that would be one way to alert me to the need to add another check.
I’ve been trying to think of a nice way to allow wp-CaTT to be flexible about what it can recognize and match against. One issue is that the $Delimiter variable needs to be set to whatever the actual delimiter is. I can’t just use a longer regexp that combines all the terms, because the plugin reassembles the original href’s with the added Technorati tags, using the delimiter. In addition, I can’t just use the list of delimiters straight, I have to regexp-ify them. In other words, the delimiter " | " has to be escaped because the vertical bar carries special meaning in regexp’s. Or the br took an optional space (” ?”) because some people put down <br /> and others <br>. Hmmm…I suppose people also put down just <br>, too… ‘k…
else if (preg_match("/<br ?\/?>/", $url))
that fixes that…
I suppose I could take the tack that the Technorati bubbles themselves become the separators, and leave the delimiter empty. But then a theme like Barthelme points out the need to preserve it anyway, because Barthelme prints each category out on its own line and the cleanness of that presentation is spoiled if the categories start wrapping instead.