经由过程函数 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',
'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>';
}
?>

评论列表