Last updated on November 28, 2011. Tags: category page, WordPress category ID, WordPress category list
The category list is one of the major components of a typical blog or any website powered by WordPress. Categories are used to classify blog posts into subjects. They can also be used in some other way such as classifying products (if you're using WordPress website as online store) and organizing photos into albums (if you have an online gallery). The category list provides a list of links to all categories with at least one entry.
In some cases, we would like to hide certain categories. Meaning, the category does really exist and can be accessed in http://domain.com/category/specific-category-name/ but the link towards it in the category list is absent. Perhaps, you intend to use those categories only in managing the blog and is therefore not intended to be accessible to your audience. Perhaps you want to hide a category because it is used only to enable another WordPress tweak such as preventing some posts from appearing in the search results.
The category list is usually in the sidebar (sidebar.php) but may also be found in some other parts of the layout. The list is generated by the following PHP code:
<?php wp_list_categories(); ?>
Sometimes, the code has some other components within the parentheses.
<?php wp_list_categories('title_li='); ?>
To hide a category, determine which category you would like to exclude. Then, add exclude=10 in the code, where 10 is the category ID of the category you wish to hide, as shown in the code below.
<?php wp_list_categories('exclude=10'); ?>
Just replace 10 with the actual category ID of the category you wish to hide. If you do not know how to determine the category ID, visit this post.
You can hide several categories, just indicate the IDs of these categories separated by comma.
<?php wp_list_categories('exclude=10,11,15'); ?>
If there are other parameters in the parentheses, you can separate them by putting ampersand (&) between them.
<?php wp_list_categories('exclude=10,11,15&title_li='); ?>
An alternative method is to hide all but few selected categories. Simply replace exclude with include and indicate the category IDs of the ones that you want to show up in the list.
<?php wp_list_categories('include=9,12,17'); ?>
Note that if you hide a parent category, all subcategories under it are also not visible in the category list. Also, categories without any posts assigned to them are also not visible.
Posted by Greten on November 30, 2009 under WordPress
Comment Rules and Reminders