WordPress get current category information tag: get_ the_ category

WordPress template tag get_ the_ Category is used to obtain the current classification information, including classification ID, classification name, classification alias, classification description, parent classification ID, number of articles under classification, etc.

get_the_category( int $id = false )

Function parameters

$id

Integer type, default value: the ID of the current article

Specify the ID of the article to return the information of the classification to which the article belongs.

Function return value

Array (
    [0] => WP_Term Object
        (
            [term_id] => 7
            [name] => 互联网
            [slug] => internet
            [term_group] => 0
            [term_taxonomy_id] => 7
            [taxonomy] => category
            [description] => 聚焦互联网业界动态,关注互联网发展中的人和事,提供最新的互联网资讯,分享互联网知识和技术。
            [parent] => 0
            [count] => 38
            [filter] => raw
            [cat_ID] => 7
            [category_count] => 38
            [category_description] => 聚焦互联网业界动态,关注互联网发展中的人和事,提供最新的互联网资讯,分享互联网知识和技术。
            [cat_name] => 互联网
            [category_nicename] => internet
            [category_parent] => 0
        )
)

Examples of function usage

<?php
	$categorys = get_the_category();
	foreach ($categorys as $category) {
		echo $category->name;
	}
?>

Extended reading

get_ the_ The category() function is located in: WP includes / category- template.php

Related tags:

  • the_ category()
  • the_ category_ rss()
  • single_ cat_ title()
  • category_ description()
  • wp_ dropdown_ categories()
  • wp_ list_ categories()
  • get_ category_ parents()
  • get_ category_ link()
  • in_ category()
Related Article
WordPress comment date tag: comment_date

WordPress template tags comment_ Date is used to output the date of a comment, usually in a custom comment template. Read more

WordPress comment summary tag: comment_excerpt

WordPress template tags comment_ Excerpt is used to output the summary of comments. The default output is 20 characters. It Read more

WordPress comment time tag: comment_time

WordPress template tags comment_ Time is used to output the publishing time of the current comment, which is the same Read more

WordPress RSS format comment author name tag: comment_author_rss

WordPress template tags comment_ author_ RSS is used to output the comment author name in RSS format, which has no Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image