Sensible Use of “Tags” in a WordPress Blog

In WordPress there are categories and then there are tags. I wanted to keep my posts organized, so I did some research to try to understand the difference between tags and categories.

After reading some explanations, I still wasn’t satisfied. I couldn’t find a logical distinction between categories and tags.

So here’s what I decided to do…

Why it’s enough to just use tags and ignore categories

Categories and tags are essentially the same thing. Using both to organize posts is an overkill. Just use one — the more versatile. That would be tags. As for the categories, I’m letting all my posts fall under Uncategorized.

Tags are more concise and descriptive than categories. And after some time, the tag cloud gives very accurate visual depiction of the topics covered on a blog. The tag cloud tells what a blog is (mostly) about.

But to get the most out of tags and the tag cloud, some customization is required.

Theme customization

Themes come pre-equipped to handle categories. The theme I use on this website, showed the categories under each post. It showed the tags at the top (for SEO purposes, supposedly). I removed the categories and brought the tags to the bottom, where categories were. I renamed tags to Topics, as you can see at the end of each post.

Obviously, this required editing of the theme files.

Creating a Usable Tag Cloud Widget

The default WordPress tag cloud is ugly. That’s why very few websites use it. That’s a shame because like a said, a tag cloud can be very useful. That’s why I took some time to fix the tag cloud on this website and make a real use of it.

Here’s a sample of what I created

Most popular topics appear first and with the largest font size. Then topics that are not covered as much appear later in the list and with smaller font size. Of course, this tag cloud changes as the variation of topics on the blog changes. After all, that’s the nature of a tag cloud.

One would think creating a tag cloud like that should be simple, right? Well, not if you want the topics to be comma-separated like mine are.

My custom made tag cloud widget

This tag cloud has the following features:

  • Tags are comma separated
  • Most popular tags appear first in the list

Here’s the code for the widget:

[php]aadd_action(‘widgets_init’, create_function(”, ‘register_widget(“MX_Tags_Widget”);’));
class MX_Tags_Widget extends WP_Widget
{
function MX_Tags_Widget() {
parent::WP_Widget(false, $name = ‘MX Tag Cloud’);
}

function widget($args, $instance)
{
extract($args);
extract($instance);

echo $before_widget;

// My widget says, “This Website is (Mostly) About”.
// You can change that to anything you want.
echo ‘<h2 class=”widgettitle”>This Website is (Mostly) About</h2>’;

// You can change the behavior of this tag cloud widget
// by passing different parameters
// See a list of possible parameters at
// http://codex.wordpress.org/Template_Tags/wp_tag_cloud
$tags = wp_tag_cloud(‘echo=0&format=array&largest=1.4&smallest=1&unit=em&orderby=count&order=DESC&number=20′);

// This is what separates the tags by commas.
// You can change the separator to any other character
// The separater is wrapped in a designated class
// to make CSS styling possible.
$tags = implode(‘<span class=”tag-separator”>,</span> ‘, $tags);
echo $tags;

echo $after_widget;
}

function update($new_instance, $old_instance)
{
return $new_instance;
}
}[/php]

You can simply copy this code to the functions.php file in your theme, and it will create a tag cloud widget which you can add to your sidebar from WordPress’s widgets menu.

Make sure that you read the comments within the code. They provide more tips on customization.

More to come…

I think this tag cloud is already better than a simple list of categories, especially for a personal blog like this. But it could be improved even further.

For example, now users can click on a tag and see all the posts which belong to that tag. Wouldn’t be cool if they can select more than one tag and pull all posts that belong to the selected tags? That would require more customization and coding. I’ll post about it if I ever get to it :)

Do any of these posts interest you, too?

  1. Clean Your WordPress Sidebar to Improve Navigation and SEO!
  2. WordPress Mailing List Builder Support
  3. Easy WordPress Mailing List Builder
  4. Fix Yet Another Related Posts Plugin (YARPP) Widget and Add it to the Sidebar