wordpress获得指定分类函数:get_category()


【函数介绍】

获得指定分类,以数组或是对象的形式返回。

【函数用法】

  1. <?php get_category( $category, $output, $filter ) ?>

【参数】

$category
(integer|object) (必须) 分类ID或者分类数据对象
默认: None
$output
(string) (可选) 输出格式,可以是: OBJECT, ARRAY_A, 或者 ARRAY_N
默认: OBJECT
$filter
(string) (可选)默认是 raw 或者 wordpress如果没定义过滤器filter会提供.
默认: ‘raw’

【返回值】

返回值为$output参数来定义
这里主要讲一下对象类型的返回值,
都有注释,请自行参阅。

  1. stdClass Object
  2. (
  3. //ID 分类和标签混编
  4. [term_id] => 5
  5. //分类名
  6. [name] => Cat Name
  7. //分类别名
  8. [slug] => cat
  9. //N/A
  10. [term_group] => 0
  11. //同 term_id
  12. [term_taxonomy_id] => 5
  13. //分类法,也就是分类还是标签
  14. [taxonomy] => category
  15. //分类描述
  16. [description] =>
  17. //父级ID
  18. [parent] => 70
  19. //N/A
  20. [count] => 0
  21. //分类ID
  22. [cat_ID] => 5
  23. //N/A
  24. [category_count] => 0
  25. //同 description
  26. [category_description] =>
  27. //同 name
  28. [cat_name] => Category Name
  29. //同 slug
  30. [category_nicename] => category-name
  31. //同 parent
  32. [category_parent] => 70
  33. )

【源代码】

get_category() 位于 wp-includes/category.php.