the_category()
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).
Uses: get_the_category_list()
1 time — 0.006019 sec (very slow) | 50000 times — 16.46 sec (slow) | PHP 7.1.2, WP 4.7.3
No Hooks.
Return
null
. Ничего (null).
Usage
the_category( $separator, $parents, $post_id );
- $separator(string)
- Separator between the links.
Default: '' - displays links in the <ul> list - $parents(string)
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)
-
- $post_id(int)
- ID of the post whose categories you want to display.
Default: false - current post ($post->ID)
Examples
#1 Comma separated list of post categories:
<p>Categories: <?php the_category(', '); ?></p>
#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'); ?>
#3 Set 'single' in the second parameter
<?php the_category(' > ', 'single'); ?>
Result: Poets > Pushkin (link will lead to the category "Pushkin")
Changelog
Since 0.71 | Introduced. |
the_category() the category code WP 6.3
function the_category( $separator = '', $parents = '', $post_id = false ) { echo get_the_category_list( $separator, $parents, $post_id ); }