A Tag System Based on Categories

I have managed to put together a complete tag system built on top of WordPress categories. Using both plugins of my own and plugins written by others, I was able to build a system that can show all tags, show popular tags, show tags for each post, show related tags for each post, build Technorati tags, and easily add tags to a post via the administration interface. The first step was to decide that I wanted to use tags. This happened for me after interviewing Jonas Luster, product manager for Technorati and all-around good guy. One of my questions to Jonas was “What are some of the new trends in blogging that will become big in the next year or two?” His answer in part was “most definitely tagging.” When he first said this, I didn’t really understand why, but after looking into it, I realized how important tags are to building social networks, promoting social classification, folksonomy, and distributed classification. That’s when I realized the real value of tags and decided to change my wordpress installation from a category based system (and indeed mindset) to a tag based system.

When I started working on this project, I didn’t realize that there were a multitude of plugins out there that allow one to add a tag system to wordpress. I’m glad I didn’t know this because I might not have spent the time building my own. All of the tag systems I’ve seen are seperate from WordPress categories, which I don’t like very much. I wanted to use something based on the built-in category system because I had already posted a few entries and I didn’t want to have to go back and re-tag everything. Of course, some of the plugins out there have built-in tools to do this for you, but nontheless, I was determined to build a tag system on top of WordPress categories. I was able to do so without modification to the core WordPress files or the database. This was one of my personal requirements because I didn’t want to mess things up for myself if I were to upgrade.

I’ve broken things down into two main categories (no pun intended) The first being steps for administration and the second being steps for displaying tags on the blog. Okay, on to the good stuff.

Steps for Administration
Step 1. (optional but recommended)
The first step is to set your category base to /tag. You can do this under options->permalinks.

Step2.
Install the very wonderful cat2tag plugin. This plugin removes the category list on the right side of the admin panel when writing a post and replaces it with a tag system underneath your post box very much like the way Del.icio.us tags look).

Steps for displaying tags
Step 1.
I’ve created a plugin, (very much in its alpha stages, so USE AT YOUR OWN RISK) to display popular tags, related tags, and build technorati tags–all based on the built-in wordpress category system. It contains the following functions:

show_tags($limit)
This function displays tags for the current post, along with an rss feed for each tag and it builds a technorati tag as well. Feel free to steal the image I use to display Technorati tags for your own use.

related_tags($id, $rlimit=0, $before=’’, $after=’’)
This function displays a list of related tags for the current post. I use it like so:

< ?php related_tags($post->ID, 15, ‘’, ‘’); ?>

This function was tricky, and I ultimately use the sql provided by LaughingMeme in this post. This function is very very very alpha, but it seems to be holding together for the time being. We’ll see what happens as my tag list grows.

popular_tags()
Of course I use popular tags, which I’ve rolled into this plugin. I also made a small change to the code so that popular tags get displayed in alphabetical order. Directions on using the popular tags plugin can be found here.

Step 2.
I also use the weighted tags plugin by Matt Kingston, but I’ve modified it slightly to fix a bug, you can get my modified version here. I use this plugin to display tags on my archives page, which is in much need of a redesign by the way.

That about does it. That is how I’ve implemented a full-blown tagging system on squible. The plugin I’ve written is very very alpha, so please don’t ask me to support you, I’m still figuring it out myself, but you are more than welcome to use it. If anyone adds aything to this plugin or has ideas for adding something, please let me know–I’m all about making this system as useful as possible.

A Tag System Based on Categories

Leave a Reply

Your email address will not be published. Required fields are marked *