WordPress.org

Support

Support » Themes and Templates » tag cloud of specific category page

tag cloud of specific category page

  • Hi everybody

    just spent a few hours of searching and scripting and thought you might be looking for it to.
    i wanted a tag cloud on my category page, which only shows the tags used in the posts of this category.

    put this in your category.php file wherever you want it.
    (please make sure, not to lose this code with a WordPress update)

    <?php
    	//get category name
    	$catname = get_category(get_query_var('cat'))->name;
    	//get all tags in this category
    	query_posts("category_name=$catname");
    	if (have_posts()) : while (have_posts()) : the_post();
            $posttags = get_the_tags();
    		if ($posttags) {
    			foreach($posttags as $tag) {
    				//Get Tag ID
    				$all_tags_arr[] = $tag -> term_id;
    			}
    		}
    	endwhile; endif;
    	//remove duplicates
    	$tags_arr = array_unique($all_tags_arr);
    ?>
    
    <?php
    	//get tag cloud with tag IDs in $tags_arr
    	$args = array('include'  => implode(',',$tags_arr) );
    	wp_tag_cloud($args);
    ?>

    hope this helped 🙂

  • The topic ‘tag cloud of specific category page’ is closed to new replies.