WordPress.org

Ready to get started?Download WordPress

Forums

tag cloud of specific category page (1 post)

  1. vaneess
    Member
    Posted 1 year ago #

    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 :)

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by vaneess
  • This topic is not a support question
  • WordPress version: 3.5.1