Some fixes and extensions for Wordpress tags such as a tag cloud using only tags found in a specific category and also tag and category intersection.
Download Plugin Now from Wordpress.org!
Version 0.5 enables true ‘or’ tag intersection when using a category. It wasn’t working prior to this (and no-one noticed). Thanks to Joel Giddey for spotting it.
Wordpress 2.3 introduced native tagging support, which is rather nifty.
But did you know that you can display multiple tags in the one archive and even generate a feed for that?
- “
http://your-blog-uri/?tag=tag1,tag2” this would get all the posts tagged with tag1 or tag2. - “
http://your-blog-uri/?tag=tag1+tag2” this would get all the posts tagged with tag1 and tag2 - “
http://your-blog-uri/?tag=tag1,tag2&feed=rss” this would get you an RSS feed for all the posts tagged with tag1 or tag2
Neat huh? But did you notice that on the generated tag page you see only one tag listed in the header? This function fixes that and displays all tags used to generate that tag archive. It does this by silently modifying the single_tag_title template tag. It’ll even work on the RSS feed generated by that page!
What would be also be cool is to be able to intersect categories and tags so you could grab posts with tags from a specific category for example?
With this plugin you can. It’s not perfect however. It only allows intersection between a single category and one or more tags. Technically Wordpress should be able to support multiple categories and tags intersections but it didn’t work for me in Wordpress 2.3.x and 2.5.
So go to one of your category pages. If your using using fancy permalinks then at the end of the url add “?tdo_tag=a_tag“. If your not using permalinks then you can just use “&tdo_tag=a_tag“. You must use the tag slug, not the full tag name. You can use multiple tags as above using “,” and “+”.
- Example not using fancy permalinks: “
http://your-blog-uri/?cat=35&tdo_tag=tag1,tag2” this would get all posts in category with id 35 and tagged with either tag1 or tag2. - Example using fancy permalinks: “
http://your-blog-uri/category/mycategory/?tdo_tag=tag1+tag2” this would get all posts in the category “mycategory” and tagged with both tag1 and tag2.
This plugin uses this intersection code to automatically modify the built-in tag cloud template tag wp_tag_cloud so that if it is used on a category archive, it shows only the tags within that category. You can then click on a tag in that tag cloud and it will get the posts for in that category that tagged with that tag. (You can disable this and just use the specific template as you need).





Thank you very much for your work.
this is fabolous thank you.
Thanks for the quick reply! I tried that and it didn’t work for me. It didn’t break anything, just didn’t do the rewrite, and simply returned the 404 page. By the way, I’m assuming you meant “tdo_tag” not “td_cat”. I tried both anyway.
But I did find this in the Codex:
http://codex.wordpress.org/Custom_Queries#Permalinks_for_Custom_Archives
It seems like what I’m after, but not sure where something like that would go (obiously changing the function names etc). I’m thinking the most obvious place is in your plugin somewhere (duh!).
I tried adding a suitably edited version of the above sample just to the end of your plugin, but that didn’t work either (not that I expected it to).
(There’s also http://codex.wordpress.org/Function_Reference/WP_Rewrite).
I think we’re getting closer.
I also had a look at the Search Permalink plugin:
http://wordpress.org/extend/plugins/search-permalink/#post-2433
I think a rejig of that might work also…
I’m playing around with a few ideas and if anything work, I’ll let you know.
cheers and thanks again,
Michelle (The Boss)
I’m sure there is a nice wordpress way, probably hooking into wp_rewrite stuff… but also I think you can do it with .htaccess easily enough.
If you stick something like this at the top of your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^fun/(.*)$ ?td_cat=$1 [L]
</IfModule>
It should allow a url like “http://your-blog-uri/category/mycategory/fun/tag1+tag2″ to act like “http://your-blog-uri/category/mycategory/?td_cat=tag1+tag2″.
I’ve tested this piece of code below and it will redirect “/fun/tag1+tag2/” to “?td_cat=tag1+tag2″.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^fun/(.*)$ ?td_cat=$1 [L,R]
</IfModule>
But this isn’t exactly what you want. Dropping the R should do the trick though.
Hi, Your plugin is solving a major problem I had. Thanks. But I had a question about URL structure. Instead of having it output the URL as:
“http://your-blog-uri/category/mycategory/?tdo_tag=tag1+tag2″
Could it output as:
“http://your-blog-uri/category/mycategory/tdo_tag/tag1+tag2″
??
In this way, I can change the “tdo-tag” bit to a general keyword for my niche (for example, I have a games site, so a generic word like “fun” or “play” would be appropriate). Then I’d have SEO-friendly (and human-friendly) URLs for these intersections (I’d like them to be links in my menus).
So the desired URL might be:
“http://my-blog-uri/category/puzzles/fun/adventure″
where “puzzles” is the category and “adventure” is the tag that I want to produce an interaction of.
And similarly,
“http://my-blog-uri/category/puzzles/fun/adventure+kids″
would be the intersection of the category “puzzles” with the tag “adventure” AND “kids”.
(For the record, for SEO, I’m also renaming the category and tag bases to more relevant keywords).
I’m happy to fiddle the .htaccess if that’s required (but am having difficulty doing so). I just don’t know enough php or javascript to hack your wonderful plugin
Thanking you heaps and heaps in advance,
The Boss
I commented out the if/isset lines as instructed, but that didn’t fix it.
I had not modified $tdotf_tag_get_var, nor did I comment it out.
I commented out:
$tdotf_fix_tag_cloud_auto = true;
and the tag clouds are now the same everywhere, so that worked - thanks.
I noticed a couple code blocks that were commented out, but I’m assuming that’s intentional.
How very odd. I wonder if it’s an issue with WP 2.3.2 as I’m still using 2.3.1. What you might try and do is modify the function tdotf_tag_cat_intersect. You can see it’s wrapped by:
if(isset($tdotf_tag_get_var)) { . . . }If you try commenting those lines out so we can make sure the code is actually being used.
Have you modified “$tdotf_tag_get_var”?
Thanks Mark, I’ll give that a shot. As for an example, here’s one:
http://philip.yurchuk.com/category/software/?tdo_tag=job-trends
You can see it shows everything for that category, not just the one post tagged “job trends”.
Oh dear. Looks like $tdotf_fix_tag_cloud_auto isn’t working as I thought. You can try just commenting out the line, like this.
#$tdotf_fix_tag_cloud_auto = false;
As for the tag filtering, is there any chance you could give me a link to have a look?
This plugin is perfect for my needs, however, I cannot get it to work. Using http://URL/category/catname/?tdo_tag=tagname fails. The title is correct (e.g., Music tagged with ‘concerts’). However, the tag filtering never takes place. It always shows the entire category archive. I’m using WP 2.3.2.
Also, I’m getting the modified tag clouds for categories, even though I set:
$tdotf_fix_tag_cloud_auto = false;
I’m not sure what I’m doing wrong. Thanks in advance.