In which I customize Wordpress to deal with my site prior to fully implementing tagging

WordPressI was very happy to see that the WordPress developers added the ability to “tag” posts. For a long time I’ve been using my own bastardized version of Bunny’s Technorati Tags to add tags to this site. A few days ago I decided to bite the bullet and convert to using the tag system that is now baked into this CMS.

It’s a much more “visitor friendly” implementation of tagging …

Here’s my only problem: The standard WordPress tagging engine is designed so that clicking a tag on a post displays an archives page with all of the other posts tagged with that tag. (Confused yet?) I don’t like that. One reason I don’t like that is because I have not yet managed to transfer all of my tags from the old system to the new, so lots and lots of my posts have no tags. That means if you click a tag for “ovulating kleptomaniac”, for example, you’re not going to get any results. So I have hornswaggled the code a bit to make it so that on this site the tags link to search results for that tag instead. I think it’s a much more “visitor friendly” implementation of tagging.

It’s pretty simple to do it, if you’re interested. In your index.php template (and archive.php, search.php, etc.), within the loop, instead of using the default WordPress tag display function:

<?php the_tags('Tags:', ', ', '<br>'); ?>

I am using the following:

echo "<p class=\"postmetadata\">Tagged with: ";
$posttags = get_the_tags();
if ( $posttags ){
$tagcount = 0;
foreach ( $posttags as $tag ){
if ( $tagcount ) echo ", ";
echo "<a href=\"" . strtolower($tag->name) . "\" rel=\"tag\">" . strtolower($tag->name) . "</a>";
echo "</p>";

You’ll see that I’m using the tag name property instead of the tag slug property. That’s because slug replaces a space with a hyphen and searching my site for los-angeles will not yield nearly as many results as a search for los angeles. I’m formatting everything as lowercase just because I like it better.

So there you go. I hope someone else finds this useful.

Post the first comment:

I'll never share your email address and it won't be published.

What Is This? is the personal weblog of me, David Vincent Gagne. I've been publishing here since 1999, which makes this one of the oldest continuously-updated websites on the Internet.

A few years ago I was trying to determine what cocktails I could make with the alcohol I had at home. I searched the App Store but couldn't find an app that would let me do that, so I built one.


You can read dozens of essays and articles and find hundreds of links to other sites with stories and information about Ernest Hemingway in The Hemingway Collection.