Php Wordpress:如何以逗号分隔显示类别和子类别
如何显示子类别以逗号分隔的Wordpress类别? 我得到了以下信息,但它不是每个子类别用逗号分隔的 我想从类别id“1”中指定所有内容,以逗号分隔显示所有子类别Php Wordpress:如何以逗号分隔显示类别和子类别,php,wordpress,Php,Wordpress,如何显示子类别以逗号分隔的Wordpress类别? 我得到了以下信息,但它不是每个子类别用逗号分隔的 我想从类别id“1”中指定所有内容,以逗号分隔显示所有子类别 $categories = get_categories(); // Current Category will retrive foreach ( $categories as $category ) { $cat = $category->name; // Parent Category
$categories = get_categories(); // Current Category will retrive
foreach ( $categories as $category ) {
$cat = $category->name; // Parent Category name
$category = get_category_by_slug( $cat );
$args = array(
'type' => 'post',
'child_of' => $category->term_id,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => FALSE,
'hierarchical' => 1,
'taxonomy' => 'category',
);
$child_categories = get_categories($args );
$category_list = array();
$category_list[] = $category->term_id;
if ( !empty ( $child_categories ) ){ // If child Category available
foreach ( $child_categories as $child_category ){ // Print Child Category
$category_list[] = $child_category->term_id;
echo ",". $child_category->cat_name."<br/>";
}
}
}
$categories=get_categories();//将检索当前类别
foreach($categories作为$category){
$cat=$category->name;//父类别名称
$category=通过slug($cat)获取\u category\u;
$args=数组(
'type'=>'post',
'child\u of'=>$category->term\u id,
'orderby'=>'name',
“订单”=>“ASC”,
“hide_empty”=>FALSE,
“层次结构”=>1,
“分类法”=>“类别”,
);
$child\u categories=get\u categories($args);
$category_list=array();
$category\u list[]=$category->term\u id;
if(!empty($child_categories)){//if子类别可用
foreach($child\u categories作为$child\u categories){//打印子类别
$category\u list[]=$child\u category->term\u id;
echo“,”$child_category->cat_name.“
”;
}
}
}
$childCategoriesArray=Array(); // just for sake of safety
if ( !empty ( $child_categories ) ){ // If child Category available
foreach ( $child_categories as $child_category ){ // Print Child Category
$category_list[] = $child_category->term_id;
$childCategoriesArray[]=$child_category->cat_name;
}
}
}
echo implode(',',$childCategoriesArray); // that's it - comma separated :)