WordPress获取一切分类列表函数:get_categories()
经过函数get_categories()就可以输入 WordPress 获取一切分类列表
用法
<?php $categories = get_categories( $args ); ?>
$args默许值
<?php
$args = array(
‘type’ => ‘post’,
‘child_of’ => 0,
‘parent’ => ”,
‘orderby’ => ‘name’,
‘order’ => ‘ASC’,
‘hide_empty’ => 1,
‘hierarchical’ => 1,
‘exclude’ => ”,
‘include’ => ”,
‘number’ => ”,
‘taxonomy’ => ‘category’,
‘pad_counts’ => false
);
?>
参数分析
type:(字符)post和link 此中link在新版3.0今后已被弃用。
child_of:(整数)仅体现标注了编号的分类的子类。该参数无默许值。使用该参数时应将hide_empty参数设为false
parent:(整数)只体现某个父级分类以及底下的子分类(注:子分类只体现一个层级)。
orderby:(字符)将分类按字母排序或独占分类编号举行排序。默以为按分类 编号排序包含ID(默许)和Name
order:(字符)为种别排序(升序或降序)。默许升序。约莫的值包含asc(默许)和desc
hide_empty:(布尔值)触发体现没有文章的分类。默许值为true(隐蔽空种别)。好效的值包含:1(true)和0(false)
hierarchical:(布尔值)将子类作为内里列表项目(父列表项下)的层级干系。默以为true(体现父列表项下的子类)。好效值包含1 (true)和0(false)
exclude:(字符)撤除分类列表中一个或多个分类,多个可以用逗号分开,用分类ID号表现
include:(字符)只包含指定分类ID编号的分类。多个可以用逗号分开,用分类ID号表现
number:(字符)将要前往的种别数目
pad_counts:(布尔值)经过子类中的项来盘算链接或文章。好效值包含1(true)和0(false),0为默许
taxonomy:(字符)前往一个分类法,这个是wordpress3.0版本后新添加的一个参数。前往的值包含category(默许)和taxonomy(一些新界说的分类称呼)
示例
<?php
$args=array(
‘orderby’ => ‘name’,
‘hide_empty’ => false, //体现一切分类
‘order’ => ‘ASC’
);
$categories=get_categories($args);
foreach($categories as $category) {
echo ‘<p>Category: <a href=”‘ . get_category_link( $category->term_id ) . ‘” title=”‘ . sprintf( __( “View all posts in %s” ), $category->name ) . ‘” ‘ . ‘>’ . $category->name.'</a> </p> ‘;
echo ‘<p> Description:’. $category->description . ‘</p>’;
echo ‘<p> Post Count: ‘. $category->count . ‘</p>’;
}
?>

















