Category tags
The_category()
Displays a link to the category or categories a post belongs to.This tag must be used within The Loop.
<?php the_category( $separator, $parents, $post_id ); ?>
Parameters
$separator (optional) Text or character to display between each category link.
By default, the links are placed in an HTML unordered list.
An empty string will result in the default behavior. Default: empty string
$parents (optional) How to display links that reside in child (sub) categories.
Options are:
1) ‘multiple’ – Display separate links to parent and child categories, exhibiting
“parent/child” relationship.
2) ‘single’ – Display link to child category only, with link text exhibiting “parent/child”
relationship. Default: empty string
$post_id (int) (optional) Post ID to retrieve categories. The default value false results in
the category list of the current post. Default: false
<p>Categories: <?php the_category(‘ ‘); ?></p>
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 Templatedictated by the Template Hierarchy rules.
<?php wp_list_categories( $args ); ?>
Parameters
show_option_all (string) A non-blank value causes the display of a link to all categories if the style is set to list. The default value is not to display a link to all
orderby (string)
Sort categories alphabetically, by unique Category ID, or by the count of posts in that Category. Valid values:
ID
name – Default
slug
Count
Wp_list_categories()
Parameters
style (string) Style to display the categories list in. A value of list displays the categories as list items while none generates no special display method (the list items are separated by <br> tags). The default setting is list (creates list items for an unordered list). See the markup section for more. Valid values:
list – Default
None
show_count (boolean) Toggles the display of the current count of posts in each category. The default is false (do not show post counts).
Valid values:
1 (True)
0 (False) – Default
Wp_list_categories()
To sort categories alphabetically and include only the categories with IDs of 16, 3, 9 and 5 you could write the following code:
<ul>
<?php wp_list_categories(‘orderby=name&include=3,5,9,16’); ?>
</ul>
The following example displays category links sorted by name, shows the number of posts for each category, and excludes the category with the ID of 10 from the list.
<ul>
<?php wp_list_categories(‘orderby=name&show_count=1&exclude=10’); ?>
</ul>