the_category()WP 0.71

Displays links to the categories to which the post belongs in either HTML list or custom format.

The function should be used inside the WordPress Loop or the $post_id parameter should be passed (see description).

1 time — 0.006019 sec (very slow) | 50000 times — 16.46 sec (slow) | PHP 7.1.2, WP 4.7.3

No Hooks.


null. Ничего (null).


the_category( $separator, $parents, $post_id );
Separator between the links.
Default: '' - displays links in the <ul> list

How to show links if the current category is a child category. Can be:

  • multiple - show links to parent and child categories separately, keeping order (parent/ancestor).

  • single - show one link to the category in which the post is located, but the whole category (parent/ancestor) nesting structure becomes the anchor of the link.

Default: '' - just displays the categories to which the post belongs (no relation is taken into account)

ID of the post whose categories you want to display.
Default: false - current post ($post->ID)



#1 Comma separated list of post categories:

<p>Categories: <?php the_category(', '); ?></p>

Result: Categories: WordPress, Computers, Blogging


#2 Use the second parameter

Suppose that the post is in category "Pushkin", which is the sub-category of "Poets", then:

<?php the_category(' > ', 'multiple'); ?>

Displays: Poets > Pushkin


#3 Set 'single' in the second parameter

<?php the_category(' > ', 'single'); ?>

Result: Poets > Pushkin (link will lead to the category "Pushkin")


Since 0.71 Introduced.

the_category() code WP 6.3

function the_category( $separator = '', $parents = '', $post_id = false ) {
	echo get_the_category_list( $separator, $parents, $post_id );