Php “孙子”类别显示在所有子类别中
孙子类别显示在所有子类别中,而不是其各自的子类别中 我已经尝试循环第三级类别(孙子),但它仍然显示所有孙子到所有子类别 这是完整的代码。请确定在循环孙子类别时放置的正确代码Php “孙子”类别显示在所有子类别中,php,wordpress,multidimensional-array,Php,Wordpress,Multidimensional Array,孙子类别显示在所有子类别中,而不是其各自的子类别中 我已经尝试循环第三级类别(孙子),但它仍然显示所有孙子到所有子类别 这是完整的代码。请确定在循环孙子类别时放置的正确代码 $html = ''; $taxonomies = array( 'taxonomy' => 'product_cat' ); $args = array( 'number' => 8, 'parent' => 0,
$html = '';
$taxonomies = array(
'taxonomy' => 'product_cat'
);
$args = array(
'number' => 8,
'parent' => 0,
'hide_empty' => FALSE,
'exclude' => array( 16 )
);
$parent_product_categories = get_terms($taxonomies,$args);
$html .= '<div class="sc-tab-wrapper">';
$html .= '<ul class="sc-tabs">';
$datatab = 0;
foreach($parent_product_categories as $parentprodcat) {
$datatab++;
$top_term_id = $parentprodcat->term_id;
$top_term_name = $parentprodcat->name;
$top_term_tax = $parentprodcat->taxonomy;
$html .= '<li id="'.$top_term_id.'" class=" sc-tab-link '. ( ($datatab == 1) ? "current" : '') .' " data-tab="tab-'.$datatab.'">'.$top_term_name.'</li>';
$second_level_terms[] = get_terms( array(
'taxonomy' => $top_term_tax, // you could also use $taxonomy as defined in the first lines
'child_of' => $top_term_id,
'parent' => $top_term_id, // disable this line to see more child elements (child-child-child-terms)
'hide_empty' => false,
) );
} // end of top level foreach
$html .= '</ul>';
if($second_level_terms) {
$contenttab = 0;
$html .= '<div class="sc-tab-content-wrapper">';
foreach($second_level_terms as $row => $innerArray){
$contenttab++;
$html .= '<div id="tab-'.$contenttab.'" class="sc-tab-content '. ( ($contenttab == 1) ? "current" : '') .' ">';
foreach($innerArray as $innerRow => $value){
$html .= '<ul>';
$second_term_name = $value->name;
$second_level_term_id = $value->term_id;
$html .= '<li>'.$value->name;
$third_level_terms[] = get_terms( array(
'taxonomy' => $top_term_tax, // you could also use $taxonomy as defined in the first lines
'parent' => $second_level_term_id,
//'child_of' => $second_level_term_id,
'hide_empty' => false,
) );
if($third_level_terms) {
foreach($third_level_terms as $third_level_row => $third_level_array){
foreach($third_level_array as $third_level_key => $third_level_value){
$html .= '<p>'.$third_level_value->name.'</p>';
}
}
}
$html .= '</li>';
$html .= '</ul>';
}
$html .= '</div>';
}
$html .= '</div>';
} // end of if second leve term
//echo '<pre style="padding-left:200px;">';
var_dump($third_level_terms);
//echo '</pre>';
return $html;
$html='';
$taxonomies=数组(
“分类法”=>“产品分类”
);
$args=数组(
“数字”=>8,
“父项”=>0,
“hide_empty”=>FALSE,
“排除”=>数组(16)
);
$parent\u product\u categories=get\u terms($taxonomies,$args);
$html.='';
$html.='';
$datatab=0;
foreach($parentprodcat的父产品类别){
$datatab++;
$top\u term\u id=$parentprodcat->term\u id;
$top\u term\u name=$parentprodcat->name;
$top\u term\u tax=$parentprodcat->taxonomy;
$html.='- “.$top\u term\u name.”
”;
$second_level_terms[]=get_terms(数组(
'taxonomy'=>$top\u term\u tax,//您还可以使用第一行中定义的$taxonomy
'child\u of'=>$top\u term\u id,
'parent'=>$top\u term\u id,//禁用此行以查看更多子元素(子项)
“hide_empty”=>false,
) );
}//顶级foreach的结尾
$html.='
';
如果($second_level_terms){
$contenttab=0;
$html.='';
foreach($row=>$innerArray的二级术语){
$contenttab++;
$html.='';
foreach($innerArray作为$innerRow=>$value){
$html.='';
$second\u term\u name=$value->name;
$second\u level\u term\u id=$value->term\u id;
$html.='- '.$value->name;
$third_level_terms[]=get_terms(数组(
'taxonomy'=>$top\u term\u tax,//您还可以使用第一行中定义的$taxonomy
“父项”=>$second\u level\u term\u id,
//'child\u of'=>$second\u level\u term\u id,
“hide_empty”=>false,
) );
if(第三级条款){
foreach($third\u level\u术语作为$third\u level\u行=>$third\u level\u数组){
foreach($third_level_数组作为$third_level_key=>$third_level_值){
$html.=''.$third_level_value->name.';
}
}
}
$html.='
';
$html.='
';
}
$html.='';
}
$html.='';
}//如果第二级术语结束
//回声';
var_转储(第三级条款);
//回声';
返回$html;
预期结果应该是孙子类别应在其各自的子类别上列出,而不是向所有子类别显示所有孙子类别。尝试“深度”=>1,//仅显示一级层次结构
这将告诉您的查询只调用一个级别。尝试“深度”=>1,//只显示层次结构的一个级别
这将告诉您的查询只调用一个级别。可能是从那里开始的。下面有一些用法可能是你从那里做的。下面有一些用法