How to Use the WordPress Categories Template Tag

By Lisa Sabin-Wilson

WordPress lets you create categories and assign posts to a specific category (or multiple categories). Categories provide an organized navigation system that helps you and your readers find posts you’ve made on certain topics.

The <?php wp_list_categories(); ?> template tag lets you display a list of your categories by using the available parameters and values. Each category is linked to the appropriate category page that lists all the posts you’ve assigned to it. The values that appear in bold are the default values set by WordPress.

Parameter and Type Possible Values Example
Determines how the category list will be ordered.
wp_list_categories(‘orderby=name’); ?>
Displays the list of categories by name, alphabetically, as
they appear on the Dashboard.
Determines the format of the category list display.
<?php wp_list_categories
(‘style=list’); ?>
Displays the list of category links where each link is
surrounded by the <li> </li>
HTML tags.
wp_list_categories(‘style=none’); ?>
Displays the list of category links with a simple line break
after each link.
Determines whether to display the post count for each listed
true or 1
false or 0
wp_list_categories(‘show_count=1’); ?>
Displays the post count, in parentheses, after each category
list. Espresso (10), for example, means
that there are ten posts in the Espresso category.
Determines whether empty categories should be displayed in the list
(meaning a category with zero posts assigned to it).
true or 1
false or 0
wp_list_categories(‘hide_empty=0’); ?>
Displays only those categories that currently have posts
assigned to them.
Determines whether the RSS feed should be displayed for each
category in the list.
Default is no feeds displayed.
wp_list_categories(‘feed=rss’); ?>
Displays category titles with an RSS link next to each
Provides the path/filename for an image for the feed.
No default <?php
Displays the feed.gif image for
each category title. This image is linked to the RSS feed for that
Determines whether the child categories should be displayed after
each parent category in the category link list.
true or 1
or 0
wp_list_categories(‘hierarchical=0’); ?>
Doesn’t display the child categories after each parent
category in the category list.

Here are a couple of examples of tags used to display a list of your categories.

This example, with its parameters, displays a list of categories sorted by name without showing the number of posts made in each category; the example also displays the RSS feed for each category title:

<?php wp_list_categories('orderby=name&show_count=0&feed=RSS'); ?>

This example, with its parameters, displays a list of categories sorted by name with the post count showing and shows the subcategories of every parent category:

<?php wp_list_categories(‘orderby=name&show_count=1&hierarchical=1'); ’>