Wordpress Category Template Tags - Best Blogs Asia
Useful reference guide for Wordpress theme development for Category Template Tags.
The following is a useful reference guide for Wordpress theme development, based upon the Category Template Tag section of the Wordpress.org Codex.
Wordpress Category Tags
Post Category
Label: the_category();
Code: <?php the_category(’arguments’); ?>
Displays a link to the category or categories a post belongs to. This tag must be used within The Loop.
Post Category in RSS Format
Label: the_category_rss();
Code: <?php the_category_rss(’arguments’); ?>
Displays the name of the category or categories a post belongs to in RSS format. This tag must be used within The Loop.
Page Category Title
Label: single_cat_title();
Code: <?php single_cat_title(’prefix’, ‘display’); ?>
Displays or returns the category title for the current page. For pages displaying WordPress tags rather than categories (e.g. “/tag/geek”) the name of the tag is displayed instead of the category.
Category Description
Label: category_description();
Code: <?php category_description(category); ?>
Displays or returns the category title for the current page. For pages displaying WordPress tags rather than categories (e.g. “/tag/geek”) the name of the tag is displayed instead of the category.
Category Dropdown
Label: wp_dropdown_categories(’arguments’);
Code: <?php wp_dropdown_categories(’arguments’); ?>
Displays a list of categories in a select (i.e dropdown) box with no submit button.
Category Link List
Label: wp_list_categories();
Code: <?php wp_list_categories(’arguments’); ?>
The template tag, wp_list_categories, displays a list of Categories as links. When a Category link is clicked, all the posts in that Category will display on a Category Page using the appropriate Category Template dictated by the Template Hierarchy rules.
If In Category
Label: in_category();
Code: <?php if ( in_category(’category_id’) ): ?>
Returns true if the current post is in the specified Category. Normally this tag is used within The Loop, but the $post variable must be set when using this tag outside of the loop.
Category’s Parents List
Label: get_category_parents();
Code: <?php echo(get_category_parents(category, display link, separator, nice name)); ?>
Returns a list of the parents of a category, including the category, sorted by ID.
Category Array
Label: get_the_category()
Code: <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ‘ ‘; }?>
Returns an array of objects, one object for each category assigned to the post. This tag must be used within The Loop.

