Wulf's Webden

The Webden on WordPress

Tag Helper

At the end of every blog post, you’ll find a number of links. The very last section, which looks like [/computers] permanent link, is part of the Blosxom blog engine that I use for this part of my site. Every post has a category and there’s also a permanent link that allows you to refer to a specific article.

Just above that is a section that starts Tags:. These all link to Technorati, an online service that pulls together what people are blogging about by the themes they cover (as represented by their choice of tags). I use it in the vain hope that I might spot someone else commenting on one of my postings and also, more practically, to see what else people have been writing about the subjects I’ve covered. For example, are there other people out there preparing to walk the later this year, reflecting on past journies or even walking it right now?

The tags have a particular format and look like this: <a href=”http://technorati.com/tag/camino+de+santiago” rel=”tag”>Camino de Santiago</a>. Having a link back to Technorati is optional: it could point anywhere, although it provides a convenient way to join the online “conversation”. The important part is rel=”tag”. This is a microformat that allows other systems to read my page and recognise that I’m contributing to a particular part of the blogsphere.

So, putting tags on the post is a useful addition. However, it’s also a pain in the neck to do manually, so I’ve written a perl script to take care of it for me. I have another script that publishes my posts to the appropriate directory on my webserver and, if I pass it a list of tags like “this,that,the other”, it will pass the file through the script below with the command echo “taglist” | ./tags.pl >> blogentry.txt. This is an easy way to include tags in my post; a recent update to the script also makes sure that spaces inside the href attribute are replaced by + markers, keeping the HTML valid.


# Take a comma separated input string and return an XHTML block
# for Technorati tags. Spaces marked with “+” in href attribute.
# Wulf Forrester-Barker, 20060502

use strict;

my $taglist = “”;
my $tags = “”;
my $tag = “”;
my $spacetag = “”;
my @tags;

while (defined($taglist = <>)) {
$tags .= $taglist;

@tags = split /,/,$tags;
$taglist = “”;
foreach $tag (@tags) {
if (!$taglist == “”) { $taglist .= “, “; }
$spacetag = $tag;
$spacetag =~ s/ /+/g;
$taglist .= “<a href=”http://technorati.com/tag/$spacetag” “;
$taglist .= “rel=”tag”>$tag</a>”;

print “n<p><strong>Tags:</strong> $taglist</p>n”;

You’re very welcome to use and adapt the script as you wish. Perhaps you could tag any posting about it as perltag so I can see how it travels!

Comments are closed.