the_category

CATEGORY TAG

What It Does

Displays the name and a link to the category that the post is filed under. If the post is filed under more than one category, all the categories will be displayed. the_category must be used within The Loop.

Code

<?php the_category(‘separator’, ‘parents’ ); ?>

Using the_category tag, you must first define your seperator, as shown above. The seperator is the character(s) that are shown in between multiple category names. For example, this can be a space or a comma.

You can then define whether ‘parents’ is multiple or single. Single is used by default.

‘multiple’ displays links to both the parent and child categories, for instance, if a post is filed under a category that is a child of a parent category.

‘single’ displays a link to only the child category, which is the exact category the post is filed under. This is used by default.

Example

The following example will display all of the categories that a post is filed under, seperated by a space.

<p>Filed in: <?php the_category(‘ ‘); ?></p>

The above example would display something like this:

Filed in: News Internet

In a similar example, we can use a comma and a space as the seperator:

<p>Filed in: <?php the_category(‘, ‘); ?></p>

The above example would display something like this:

Filed in: News, Internet

Of course, the verbage surrounding the_category tag can be changed to whatever you like.