How to Fix The TechnoTag Plugin

I found that the TechnoTag plugin had a bug in it when I tried to place multiple tags within the same post. Every tag linked to the first tags target. If I had 3 tags linking to “Spiders”, “Bugs”, and “Spooky” – then all three tags would link to “Spiders”.

After looking at a discussion about TechnoTags, I had found that other people had the same problem as well. No one had a solution so I started taking a look at the PHP code. I don’t know how I get myself into these messes sometimes. It builds out of necesity. I really like tagging my entries, so I couldn’t settle for a buggy plugin.

It appears that the author tried to solve another problem regarding how to encode tags to be xhtml friendly. It solved the problem, but another problem arose. He only took the first tag into account.

After learning a few things about regular expressions, I came up with a solution that looped through each match of a regular expression. Regular Expressions are a way of detecting patterns within text. I later found out about another method that passed a matching piece of text to another method in the code. I setup a special method to alter the text passed to it. Once that was done, things looked a little bit cleaner.

The following is the new code that I replaced the technotag($text) function with:

2 function technotag($text) {
3 $pattern = ‘/<ttag[^>]*?(\s+word=”([^"]*)”)?[^>]*?>(.+?)<\/ttag>/i’;
4 return preg_replace_callback($pattern, ‘technotagreplace’, $text);
5 }
6 function technotagreplace($match){
7 global $ttag_image_small, $ttag_link;
8 $tag = $caption = $match[3];
9 if($match[2] != “”) $tag = $match[2];
10 return ‘<a href=”‘ . $ttag_link . urlencode($tag) . ‘” rel=”tag” title=”See posts from other blogs talking about &quot;’ . $tag . ‘&quot; on Technorati.com”>’ .
11 $caption . ‘<img src=”‘ . $ttag_image_small . ‘” style=”vertical-align:middle;padding-left:2px;padding-right:2px;border-width:0px;” alt=”‘ . $ttag_alt . ‘” /></a>’;
12 }

7 Responses to “How to Fix The TechnoTag Plugin”

  1. I’d like to see you put up a page that lists your active plug-ins… Your configuration is getting more interesting every day.

  2. Oh, you can also get Gravatars back into your comments with a WP plug-in for that.

  3. Sorry to comment bomb you, but I just realized that in my first comment I forgot to mention “there’s a plug-in for that, too!” – I think I saw one that will list your active plug-ins for you.

  4. Lewie says:

    It’s ok. I’m still in the middle of fixing my templates back to how they were at blogger and haloscan. Gravatars are one thing that I will be working on.

  5. [...] The other day I had made a tweak to the TechnoTag plugin for WordPress. As I am using the plugin heavily, I had found another feature that I needed. Any space and comma are treated as delimiters for a list of tags in the ttaglist custom field for each post. I wanted to add a phrase with spaces. The first thing that I tried was to put quotes around it, but it didn’t work. [...]

  6. John says:

    I tried installing this function and keep getting an parsing error on “line 17″. The above example is a little bit difficult to cut and paste, although I tried. I haven’t been able to resolve the parsing problems since I know little about the php language and structure syntax.

  7. [...] I have now added some automated Technorati integration to this Wordpress blog which will hopefully make it more integrated with a tag based internet. I addded the Wordpress TechnoTag which allows you to add <ttag>’s around a term that relates to the subject of the post or comment. The TechnoTag plugin has a little bit of breakage though. It will make subsequent tags link to the first tag name in a post. There is a fix listed here which you can use to patch it up. Do take care to convert the fancy quotes to real ones so PHP doesn’t s|it the bed on you. [...]