Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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_Plugins_Woocommerce - Fatal编程技术网

Php 电子商务的子类别显示不正确

Php 电子商务的子类别显示不正确,php,wordpress,plugins,woocommerce,Php,Wordpress,Plugins,Woocommerce,你能告诉我这个代码有什么问题吗?我可以查看类别,但子类别作为类别的名称 $orderby = 'name'; $empty = 0; $args = array( 'orderby' => $orderby, 'show_count' => $show_count, 'hide_empty' => $empty, ); $all_categories = get_terms( 'product_cat', $a

你能告诉我这个代码有什么问题吗?我可以查看类别,但子类别作为类别的名称

$orderby      = 'name';
$empty        = 0;

$args = array(
    'orderby'      => $orderby,
    'show_count'   => $show_count,
    'hide_empty'   => $empty,
);
$all_categories = get_terms( 'product_cat', $args );

$html = '';
if (count($all_categories))
{
    $array = $all_categories;
    foreach($all_categories as $category)
    {
        if($category->parent == 0)
        {
            $html .= '<div class="checkbox"><label><input type="checkbox" class="product-cageories" value="'.$category->term_id.'"> '.$category->name.'</label></div>';
            $j = 0;
            foreach($array as $index => $child)
            {
                if($child->parent == $category->term_id)
                {                           
                    $html .= '<div class="checkbox"><span class="pull-left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><label><input type="checkbox" class="product-cageories" value="'.$category->term_id.'"> '.$category->name.'</label></div>';
                    unset($array[$index]);
                }

                if($child->term_id == $category->term_id)
                {
                    unset($array[$index]);
                }
            }
        }
        else
        {
            continue;
        }
    }
}
echo $html;
wp_die();
$orderby='name';
$empty=0;
$args=数组(
'orderby'=>$orderby,
'show_count'=>$show_count,
“hide_empty”=>$empty,
);
$all_categories=get_术语('product_cat',$args);
$html='';
if(计数(所有类别))
{
$array=$all_类别;
foreach($category作为$category的所有类别)
{
如果($category->parent==0)
{
$html.=''.$category->name';
$j=0;
foreach($index=>$child的数组)
{
如果($child->parent==$category->term\u id)
{                           
$html.=''.$category->name';
未设置($array[$index]);
}
如果($child->term\u id==$category->term\u id)
{
未设置($array[$index]);
}
}
}
其他的
{
继续;
}
}
}
echo$html;
wp_die();
我已经在图片中介绍了这个问题。 先谢谢你

以下是解决方案 取代已打印类别的子类别

$orderby = 'name';
$empty = 0;
$args = array( 'orderby' => $orderby, 'show_count' => $show_count,
       'hide_empty' => $empty, ); 
$all_categories = get_terms( 'product_cat', $args ); 
$html = '';
if (count($all_categories)) {
$array = $all_categories; 
foreach($all_categories as $category) { 
if($category->parent == 0) {
$html .= '<div class="checkbox"><label><input type="checkbox" class="product-cageories" value="'.$category->term_id.'"> '.$category->name.'</label></div>';
$j = 0; 
foreach($array as $index => $child) {
if($child->parent == $category->term_id) {  
$html .= '<div class="checkbox"><span class="pull-left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><label><input type="checkbox" class="product-cageories" value="'.$child->term_id.'"> '.$child->name.'</label></div>';
unset($array[$index]);
}
if($child->term_id == $category->term_id) {
unset($array[$index]); 
}
}
}else{ 
continue;
}
}
}
echo $html; 
wp_die();
$orderby='name';
$empty=0;
$args=数组('orderby'=>$orderby,'show\u count'=>$show\u count,
'hide_empty'=>$empty,);
$all_categories=get_术语('product_cat',$args);
$html='';
if(计数(所有类别)){
$array=$all_类别;
foreach($category作为$category的所有类别){
如果($category->parent==0){
$html.=''.$category->name';
$j=0;
foreach($index=>$child的数组){
如果($child->parent==$category->term_id){
$html.=''.$child->name';
未设置($array[$index]);
}
如果($child->term\u id==$category->term\u id){
未设置($array[$index]);
}
}
}否则{
继续;
}
}
}
echo$html;
wp_die();

到目前为止,您尝试了什么?堆栈溢出不是一种调试服务,询问“此代码有什么问题”是离题的。你应该已经研究过你的问题,并且在发帖前自己编写代码做了很好的尝试。如果你在某件特定的事情上遇到了困难,请写一份你尝试过的东西的总结和一份报告。请阅读。