Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用自定义标记和层次结构输出类别?_Php_Wordpress - Fatal编程技术网

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>&rsaquo;';
} 
尝试了此操作,但输出只是一个完全没有层次结构的项目列表:

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>&rsaquo;';
        } 
    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">