As of this post, wordpress does not have a built in function to make a tag cloud from a specfic category. This is one of the few ways it can be done.
The Method
Make a query for the category and then make a custom loop to go through all the posts from that category. Inside your custom loop echo out the tags from each post. Once thats done, don’t forget to reset the query; otherwise it cant be used again on the same page.
<?php
query_posts('category_name=BLANK'); //Category query
if (have_posts()) : while (have_posts()) : the_post(); // Custom loop
if( get_the_tag_list() ){
echo $posttags = get_the_tag_list('<li>','</li><li>','</li>'); //Tags from each post
}
endwhile; endif; //End custom loop
wp_reset_query(); //Reset query
?>
</ul>
Just put the category slug name of the category you want in where it says BLANK in category_name=BLANK and paste the code anywhere you want to have that category tag cloud.
Custom Category Tag Cloud Function
If you want it to be in a nice compact function, then put it in the functions.php file.
<ul>
<?php
$category = 'category_name=' . $category_in;
query_posts( $category );
if (have_posts()) : while (have_posts()) : the_post();
if( get_the_tag_list() ){
echo $posttags = get_the_tag_list('<li>','</li><li>','</li>');
}
endwhile; endif;
wp_reset_query();
?>
</ul>
<?php } ?>
Then call the function anywhere you want, while giving it the category slug name as a parameter.
cat_tag_cloud( 'BLANK' ); //functions.php category specific tag cloud
?>
Comment if you see a way to improve this method.
Thanks for the code. I’ve got a question: On my website, using your code, I only get a list of the tags but not a cloud. How can I do this?