Here is another helpful wordpress tip involving the “categories” template tag “the_category()”. By default, the category template tag shows which category your post is in by creating an unordered, vertical list with bullet points. Most people then control the look of the category list via css to make it better fit into the design of their theme.
Many of us will have the same post associated with multiple categories and want all of them to be displayed. The “the_category()” template tag will output all of those associated categories. But, some of us also use categories for structure… to display a post in an appropriate place in a particular theme design. For example, when you want a particular post featured you might use a category labeled “Featured” to ensure that the post shows up in a certain place on your page.
Here is the problem… unless you want the category list to display “Featured” next to it’s more appropriate category classifications you need to make a change to the category template tag’s output.
If only wordpress would allow a simple “exclude category” parameter in the template tag, but it currently does not. But, with a little extra coding you can accomplish this.
Take a look at the code below:
[php]<?php
//edit below for categories you want to be excluded
$exclude = array("Featured", "Uncategorized");
//edit below for how you want the category items separated
$separator = " | ";
//don’t edit below here!!
$new_the_category = ”;
foreach((get_the_category()) as $category) {
if (!in_array($category->cat_name, $exclude)) {
$new_the_category .= ‘<a href="’.get_bloginfo(url).’/’.get_option(‘category_base’).’/’.$category->slug.’">’.$category->name.’</a>’.$separator;
}
}
echo substr($new_the_category, 0, strrpos($new_the_category, $separator));
?>[/php]
Simply replace the “the_category()” with the above code and list the category names you want to be invisible where we have “Featured”, “Uncategorized”.
NOTE: Depending on how you have your permalinks set up, you will probably have to explicitly state “category” in the permalinks settings for the urls to work properly.