get_category()通过一个分类id或者对象获取分类所有信息

目录

描述

译文

按已知类别编号或类别对象检索类别数据。

将检索数据库的类别行对象传递给$category参数后,参数可缓存类别数据。

将类别编号的整数传递给$category后,如果类别还未缓存,该类别将会从数据库中被检索到并回传。

查看get_term() ,类别编号和类别对象都将被若干过滤器返回,并最终按$filter参数值进行审查。

转换类别以维持后台兼容性。

原文

Retrieves category data given a category ID or category object.

If you pass the $category parameter an object, which is assumed to be the category row object retrieved the database. It will cache the category data.

If you pass $category an integer of the category ID, then that category will be retrieved from the database, if it isn't already cached, and pass it back.

If you look at get_term(), then both types will be passed through several filters and finally sanitized based on the $filter parameter value.

The category will converted to maintain backwards compatibility.

Note: use get_term() to get Link Categories based on their ID's. get_category only returns Post Categories.

get_category() 描述

用法

<?php get_category$category$output$filter ?>

get_category() 用法

参数

$category

(integer|object) (必填) Category ID or Category row object

默认值: None

$output

(string) (可选) Constant OBJECT, ARRAY_A, or ARRAY_N

默认值: OBJECT

$filter

(string) (可选) Default is raw or no WordPress defined filter will applied.

默认值: 'raw'

get_category() 参数

返回值

(mixed) 

Category data in type defined by $output parameter. Returns null if $category does not exist.

get_category() 返回值

示例

Sample get_category() code


<?php $thisCat get_category(get_query_var('cat')); ?>

The variable $thisCat is now:

get_category() 示例

注意

  • 使用到: get_term() Used to get the category data from the taxonomy.
  • The count attribute includes custom post types as well if the custom post type uses standard categories.

get_category() 注意

历史

  • 添加于 版本: 1.5.1

get_category() 历史

源文件

get_category() 函数的代码位于 wp-includes/category.php.

get_category() 源文件