Viewing 3 replies - 1 through 3 (of 3 total)
  • You could modify your theme, or you automatically modify the query. For example you could add the following into the function.php of your active theme:

    add_filter( 'pre_get_posts', 'change_tag_group_for_category' );
    
    function change_tag_group_for_category( $query ) {
    
    	if ( $query->is_category() && $query->is_main_query() ) {
    
    		// set here which term groups to display; pattern: category id => term group id
    		$term_group = array(
    			1 => 2,
    			5 => 4
    		);
    
    		$posttags = get_tags();
    
    		// make array of tags for each listed category according to their groups
    		foreach($posttags as $tag)
    			foreach($term_group as $key=>$value)
    				if ($value == $tag->term_group) $query_tags[$key][] = $tag->term_id;
    
    		$category_id = get_cat_ID( $query->query_vars['category_name'] );
    
    		$query->set( 'tag__in', $query_tags[$category_id] );
    	}
    }

    (It works only if all listed tag groups contain at least one tag.)

    PS: I hope I correctly understood the question. This solution above will display posts that have tags in particular tag groups. It will not display tag groups. If you want to display tags instead, you simply display them with the function tag_groups_cloud.

    Just to conclude this topic: If you need a different tag cloud on top of the posts on category pages, you add into your theme’s category.php something like:

    <?php
    	if ( function_exists( 'tag_groups_cloud' ) ) {
    
    		$term_group = array(
    			37 => 3,
    			3 => 4,
    		);
    		echo tag_groups_cloud( array( 'show_tabs' => 0 , 'include' => $term_group[ get_cat_ID( single_cat_title('',false) ) ]) );
    
    	}
    ?>

    I hope that one of these two answers matches the question! ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Tag Groups] How to display tag groups automatically’ is closed to new replies.