WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/the category

Description

Displays a link to the category or categories a post belongs to. This tag must be used within The Loop.

Usage

 <?php the_category$separator$parents$post_id ); ?> 

Parameters

$separator
(string) (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
(string) (optional) How to display links that reside in child (sub) categories. Options are:
 ▪ 'multiple' - Display separate links to parent and child categories, exhibiting "parent/child" relationship.
 ▪ 'single' - Display link to child category only, with link text exhibiting "parent/child" relationship.
Default: empty string
Note: Default is a link to the child category, with no relationship exhibited.
$post_id
(int) (optional) Post ID to retrieve categories. The default value false results in the category list of the current post.
Default: false

Examples

Separated by Space

List categories with a space as the separator. <?php the_category' ' ); ?>

Separated by Comma

Displays links to categories, each category separated by a comma (if more than one). <?php the_category', ' ); ?>

Separated by Arrow

Displays links to categories with an arrow (>) separating the categories. Note: Take care when using this, since some viewers may interpret a category following a > as a subcategory of the one preceding it. <?php the_category'&gt; ' ); ?>

Separated by a Bullet

Displays links to categories with a bullet (•) separating the categories. <?php the_category'&bull;' ); ?>

Source Code

Changelog

  • Since 0.71
  • 2.5 : Added the post_id parameter.

Related

See also index of Function Reference and index of Template Tags.