问题概述
- 在一个普通分类(“category”)或自定义分类(“taxonomy”)的页面,获取其下级分类列表
解决方法
1、使用wp_dropdown_categories函数
<?php
wp_list_categories("child_of=".$catID."&depth=1&hide_empty=0&show_count=1&style=none&orderby=name&order=ASC&separator=");
?>
2、使用wp_list_categoriese函数
<?php
wp_dropdown_categories("child_of=".$catID."&depth=1&hide_empty=0&show_count=1&hierarchical=1");
?>
3、使用get_categories获取分类列表后遍历显示
<?php
$args=array(
'hide_empty' => 0,
'parent' => $catID
);
$categories=get_categories($args);
$catcount = 0;
$catlist = '<select onchange="window.location=this.value;">';
$catlist .= '<option value="">——下级分类列表——</option>';
foreach($categories as $category) {
$catcount = $catcount + 1;
$catlist .= '<option value="'.get_category_link($category) . '">' . $category->cat_name.'('.$category->count. ')'. '</option>';
}
$catlist .= '</select>';
?>
京公网安备 11010802027924号