制作wordpress主题时,想要获取所有分类相关信息,可以通过get_categories()函数,该函数可以返回与查询参数相匹配的类别对象数组,该函数的变量与wp_list_categories()函数基本一致,且变量可被作为数组传递,也可在查询句法中被传递。
函数用法:
$args参数及默认值:
‘post’,
‘child_of’ => 0,
‘parent’ => ”,
‘orderby’ => ‘name’,
‘order’ => ‘ASC’,
‘hide_empty’ => 1,
‘hierarchical’ => 1,
‘exclude’ => ”,
‘include’ => ”,
‘number’ => ”,
‘taxonomy’ => ‘category’,
‘pad_counts’ => false );
?>
参数说明:
示例:显示分类列表和分类描述以及包含的文章数目
‘name’,
‘order’ => ‘ASC’
);
$categories=get_categories($args);
foreach($categories as $category) {
echo ‘
- ‘;
echo ‘ name ) . ‘” ‘ . ‘>’ . $category->name.’ ‘;
echo ‘
‘;
}
?>[/cc]
输出html代码:
参考文章:
修改WordPress文章默认排序的方法