Pigsaw Blog
All the pig that’s fit to saw

I’ve added Technorati tags

Wordpress itself was a great help for this. It allows metadata to be added really easily, and consistently, in key/value pairs. And it allows each key to have multiple values.

So have a key called “Tag” and at the end of each entry I’ve added this (in index.php and single.php):

<?php
    $tags = get_post_custom_values('Tag');
    if (count($tags)) {
        echo '<p class="tags">Tags: ';
        for ($i = 0; $i < count($tags); $i++) {
            $url = 'http://technorati.com/tag/'.$tags[$i];
            echo ‘<a href="’.$url.’" rel="tag">’.$tags[$i].’</a>’;
            if ($i < count($tags)-1) echo ‘, ‘;
        }
        echo “</p>”;
    }
?>

Wordpress’s categories allow effective Atom/tagging without this. But I wanted to have arbitrary tags which might be used only once or twice ever. I didn’t want to have to set up categories for such things. That’s why I chose this route.

I’m also pleased because this is my first ever proper bit of PHP - I’ve done a for-loop! I’m still slightly disconcerted at what I think is an odd and unique feature of PHP - but nonetheless appropriate. It seems a PHP runtime error does not prevent the application continuing. I wonder if that’s right.

Anyway, I’m delighted with my tags, and I now intend to have some fun with them. Watch this space…

Tags: , , ,

Leave a Reply »»