Php 如何使用自定义标记和层次结构输出类别?
我发现了以下几点Php 如何使用自定义标记和层次结构输出类别?,php,wordpress,Php,Wordpress,我发现了以下几点 $args = array( 'orderby' => 'name', 'order' => 'ASC', 'number' => 20 // how many categories ); $categories = get_categories($args); foreach($categories as $category) { echo '<li><a href="' . get_category_link( $catego
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'number' => 20 // how many categories
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></li>›';
}
尝试了此操作,但输出只是一个完全没有层次结构的项目列表:
public function walk_taxonomy( $type = "checkbox", $args = array() ) {
$args['walker'] = new Search_Filter_Taxonomy_Walker($type, $args['name']);
$output = $argo = array(
'hierarchical' => 1
);
$categories = get_categories($argo);
foreach($categories as $category) {
echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></li>›';
}
if ( $output )
return $output;
}
public function walk\u分类法($type=“checkbox”,$args=array()){
$args['walker']=新搜索\过滤器\分类法\ walker($type$args['name']);
$output=$argo=array(
“层次结构”=>1
);
$categories=get_categories($argo);
foreach($categories作为$category){
回音“”;
}
如果(产出)
返回$output;
}
您必须将其添加到参数中:
'hierarchical' => 1,
在foreach中,您必须检查$category->parent是否为空。。如果不是空缩进,则通过添加空格或对li类应用类来缩进
<li class="indent">
即使添加的输出不是层次结构,为什么不使用:wp\u list\u categories()?您可以。。args中有walker选项
<li class="indent">