• Has anyone cracked the problem of developing a usable template that accounts for tag intersections/unions? As much as I enjoy the new functionality, it sure seems to be little more than skin and bones… are there any plugins or techniques that might be helpful here?
    Thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter Xander

    (@xander)

    Thanks, I’ve seen that already. The article is one of the only sources of information on the mechanism behind tag intersections and unions, but it doesn’t explain (to me anyway) how to put these things into practise.

    A fairly simple example to work through would involve displaying a useful description of the intersection/union being viewed i.e. “Currently displaying Tag X and Tag Y” as a title. The WP core provides a tamplate tag for single tag titles, but nothing for multiple tags.

    Is this kind of thing purposefully left to plugin authors I wonder?

    I modified the default theme in WordPress 2.3 to display a list of tags when you use multiple tags in an archive. Heres the code to do it:

    <?php $tag = get_query_var('tag');
          if(isset($tag)) {
    	$tags_in_use = split(",",$tag);
    	$tags_archive_title = "";
    	$count = 0;
    	foreach($tags_in_use as $tag_in_use) {
    		$tag_obj = get_term_by('slug', $tag_in_use, 'post_tag', OBJECT, 'raw');
    		if ( is_wp_error( $tag_obj ) ) {
    			$tags_archive_title .= $tag_in_use;
    		} else {
    			$tags_archive_title .= $tag_obj->name;
    		}
    		$count++;
    		if($count < count($tags_in_use)-1) {
    			$tags_archive_title .= ", ";
    		} else if($count < count($tags_in_use)) {
    			$tags_archive_title .= " or ";
    		}
    	} ?>
    <h2 class="pagetitle">Posts Tagged ‘<?php echo $tags_archive_title; ?>’</h2>
    <?php } else { ?>
    <h2 class="pagetitle">Posts Tagged ‘<?php single_tag_title(); ?>’</h2>
    <?php } ?>

    This would print something like this:

    “Posts Tagged ‘Character Sheet, PC or Background’”

    Here it is in operation (though this site is liable to disappear!)

    What I would love to do is have an tag archive that contains only posts from a specific category.

    Actually, using the info from that post on boren.nu, I managed to get a category archive of posts with a specific tag. i.e. a intersection of category and tag.

    It’s not perfect and it only seems to work one way, I can’t open a tag archive and intersect it with a category, it’s only a category archive filtered by tag. Which means it can really only support 1 category and multiple tags (no multiple categories). The permalink is ugly too.

    Sadly it’s not much use to me right now. I wanted to have a tag cloud per category (i.e. a cloud of tags used in that category) and then when you click on the tag in the cloud it would show the posts from that category filtered by tag. But I see no easy way to get the tags used in a category.

    Thread Starter Xander

    (@xander)

    Thanks, this is pretty cool. I’d be interested in tinkering with your code for category-specific tag viewing if you think it might be worthwhile. That’s pretty much exactly what I’d be looking to do with my site.

    I can wrap both peices of code in a plugin and put it up somewhere if you want.

    BTW I extended the tag archive title thing so that it uses a filter to silently corrects single_tag_title so if it’s multiple tags it correctly prints out multiple tags and also identifies if it is “and” or “or” (i.e. + and ,). This way means there is no modification to your theme and it fixes it in the RSS feed for the multiple tag as well.

    Grab it while it’s hot!

    I don’t know if it’s worth putting it in the WordPress.org’s plugin directory or not though.

    I’ve managed to get a tag cloud of tags that are used in a category and with the plugin, when you click on the tag it goes to a category archive filtered by that tag! I’ll update the code at some point.

    Plugin added to WordPress plugin directory. Now with category based tag cloud. Enjoy.

    Mark, thanks so much for the plugin, that’s very helpful!

    Has anyone made progress on using this to show tags that appear in multiple categories?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘2.3 Tag Intersections/Unions’ is closed to new replies.