davidgagne.net

  • About
  • Archives
  • Twitter
  • Facebook
  • bartender.live
  • GitHub
  • LinkedIn

WordPress Tags

March 26th, 2008 @ 8:47 pm PDT

WordPressI was very happy to see that the WordPress developers included 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=\"http://www.davidgagne.net/?s=" . strtolower($tag->name) . "\" rel=\"tag\">" . strtolower($tag->name) . "</a>";
$tagcount++;
}
}
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.

More posts tagged:
blogtech / code / hacks / tags / web design / wordpress / wordpresswednesday

More posts categorized:
blogging blogtech Web Design

More posts from:
March 2008 / 2008

Post navigation

Previous Post
Previous Post Robbed at the Tropicana: Part 2
Next Post
Next Post Blow My Nose

Search


Give Easily

Give Easily

Did you know that Amazon will donate to the charity of your choice when you use smile.amazon.com to do your online shopping? It doesn't cost you anything extra, and you can make a big difference just by using this link.

  • Support A Charity

© David Vincent Gagne. All rights reserved. Custom WordPress Theme by Jacket Industries.