wordpress 函数 get_category
get_category 可能我们平时接触的不多,但却是很有用,网上这个函数介绍的貌似不多,所以今天只针对官方 WordPress 英文文档做一下翻译。
函数描述
获得指定分类,以数组或是对象的形式返回。
函数使用
get_category( $cat, $out, $filter )
参数描述
- $cat:分类ID,或
- $out返回值类型[OBJECT, ARRAY_A, or ARRAY_N]
- $filter
函数返回值
这里主要讲一下对象类型的返回值,都有注释,请自行参阅。
stdClass Object
(
//ID 分类和标签混编
[term_id] => 5
//分类名
[name] => Cat Name
//分类别名
[slug] => cat
//N/A
[term_group] => 0
//同 term_id
[term_taxonomy_id] => 5
//分类法,也就是分类还是标签
[taxonomy] => category
//分类描述
[description] =>
//父级ID
[parent] => 70
//N/A
[count] => 0
//分类ID
[cat_ID] => 5
//N/A
[category_count] => 0
//同 description
[category_description] =>
//同 name
[cat_name] => Category Name
//同 slug
[category_nicename] => category-name
//同 parent
[category_parent] => 70
)
总结及文献
时间原因先写这么多,有一些不太确定的先不写以N/A代替,后面会补充,该函数官方文档: 《Function Reference/get category》
