Downloads: TDO Tag Fixes Wordpress Plugin (0.5)
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).
July 15th, 2008 at 8:59 pm
TDO tag fixes with a twist…
For those who are not familiar with TDO tag fixes, its a fantastic plugin that makes up for alot of wordpress’s shortfalls in what i like to call ‘filtering’ posts. It basically allows you specify exactly what posts you want shown bas…
Guest
July 14th, 2008 at 10:02 pm
Hi Joel
Brilliant site. Just one question, how did you get to make sub categories work with tags?
I was under the impression that tdo only works with single category intersections with one or more tags. But you’ve got sub categories working which is brilliant!
Also, I like the way the checkboxes are filtered. A very nice touch indeed.
cheers
Guest
July 14th, 2008 at 8:18 pm
Great work on the fix to the plugin, I was digging through the new code and it really is a clever bit of work with the ‘OR’ joins.
For those interested I’ve finalized my implementation of the plugin over at my site a good url example is http://travel.accommodationsphere.com/earth/south-africa/gauteng-za/ look over at the left for accommodation types which are actually tags using the tdo_tag_fix with a few mods.
Regards
JG
Administrator
July 2nd, 2008 at 9:41 am
Hi Scotjam, what is the “tag surfer” functionality? I’m not familiar with it. If I know what it does, I can see if its doable.
Guest
July 2nd, 2008 at 1:07 am
Hi!
I’d love to find out how to emulate the ‘tag surfer’ functionality that wordpress.com users have.
Any ideas? I thought it might be possible to use your plugin and add some php code to change the links associated with the tags that are displayed.
For example, I could change the hyperlink of a tag (e.g. mywebsitestag [+]) so that it will append the tag to the existing url, or I could change the hyperlink (e.g. mywebsitestag [x]) so that on clicking it, it will jump the user to the same url minus the tag selected.
does this make sense?
many thanks
scotjam
Administrator
June 16th, 2008 at 11:42 am
The code I posted is slightly incorrect. I’ve done the change and its sitting in the SVN repo, so anyone can grab the dev version right now with the fix. I’ll probably release it officially during the week.
Administrator
June 16th, 2008 at 10:38 am
I’ve got a filter implemented now that correctly updates the intersection query when you have a set of tags that are ORed instead of ANDed. I’ll add it to the SVN later today, but if your in a here, here is the actual code you can add to the plugin:
function tdotf_query_filter($where) { global $tdotf_tag_get_var,$wpdb; $tag_query = tdotf_get_tdo_tag_query(); if(!empty($tag_query) && $tag_query != false && strpos($tag_query,',')) { $tags = split(",",$tag_query); // Grab all posts with these tags $sql = "SELECT p.ID FROM $wpdb->posts p INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) INNER JOIN $wpdb->terms t ON (tt.term_id = t.term_id)"; $sql .= " WHERE tt.taxonomy = 'post_tag' AND t.slug IN ('" . implode("', '", $tags) . "')"; $sql .= " GROUP BY p.ID"; $post_ids = $wpdb->get_col($sql); // Pattern and replacement for query $pattern = "AND.*$wpdb->posts\.ID.*IN.*(.*)"; $replacement = "AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ")"; // Update query $where = preg_replace('/'.$pattern.'/', $replacement, $where); } return $where; } add_filter('posts_where_request','tdotf_query_filter');Administrator
June 16th, 2008 at 10:13 am
Hi Joel,
I’ve done some digging. Your right. Tags with an OR join do not intersect with categories. This seems true for Wordpress 2.3 too. I’ve gone through the Wordpress code and it’s not supported at all. I think I can make it work though by doing some magic with filters, so I’ll see what I can do.
Guest
June 14th, 2008 at 6:30 am
I’ve checked the bug list on trac there is one there that is is slightly relevant but not directly to this issue. So I installed a fresh WP 2.3 with a fresh tdotf on http://easymapinfo.com/wordpress23/category/cat1/ and when is use tdo_tag=tag1,tag2 I’m still getting a ‘AND’ join result.
Was thinking it may be as a result of
$args->set_query_var('tag_slug__and',$tags);on line 149 of tdotf.php but when I try tag_slug__in I get no results. I think this may have something do to with query.php around line 1126 where WP seems to only handle intersects with tag_slug__and and not ‘in’.So until I find a solution I think I’m going to modify my changed tdotf to use radio buttons and not checkboxes and limit users to one cat with one tag intersects.
But I am surprised that you had it working with your 2.3 install, was it dependant on any other plugins?
Thanks!
Administrator
June 13th, 2008 at 9:16 am
Hi Joel Giddey,
I wonder is it something to do with the version of Wordpress. It was working correctly on WP2.3 where I did the initial development. I haven’t properly tested it on WP2.5.1 yet, so maybe somethings been broken. Have you checked the bugs list?