Restricting WordPress Tags by Category

Have you ever needed to display category tags? If you want to only display the tags associated with a specific category, unfortunately the built-in WordPress functions will not suffice. Why such basic functionality has to this day not been added to WordPress is beyond me.

Thankfully, after much frustration and research, I have found a working solution using a plugin called Sensitive Tag Cloud. You can visit the plugin home page, or download the plugin from the official WordPress Plugin page.

Once you have installed and activated the plugin, access the configuration page (Appearance -> SensitiveTagCloud) and ensure that the "Restricted to current category" option is enabled.

Now to display the tags for a specific category when you're browsing that category, edit the archives.php file for your theme and find the section related to browsing by category:

          <?php /* If this is a category archive */ if (is_category()) { ?>
                <h1 class="pagetitle">Category: <?php single_cat_title(); ?></h1>

Now, right below that second line, insert the following function to call SensitiveTagCloud:

<?php
  if( function_exists("stc_widget") )
    stc_widget();
?>

You can also wrap the function in a div if you want to style it. Here's how my archive.php file looks now (minus the unrelated sections of code):

          <?php /* If this is a category archive */ if (is_category()) { ?>
                <h1 class="pagetitle">Browsing: <?php single_cat_title(); ?></h1>
<div style="background:#EAF3F3 none repeat scroll 0 0; border: 1px solid #D0D8D8; padding: 20px;">
<?php
  if( function_exists("stc_widget") )
    stc_widget();
?>
</div>

And with those changes, here's how my Category pages now look:

This allows for browsing the tags associated with a specific category, while eliminating irrelevant tags. I write on a variety of topics, so there are a lot of tags that are unrelated or that would be out of context. For example, the "Blogging" tag in the Personal Development category would likely mean something different than the same tag in the Technology category (the latter having more to do with technical things like this article on WordPress).