2016-09-19 190 views
0

我有一個Woocommerce網站。在my.domain.com/shop我有一個菜單顯示所有類別。當點擊主類別時,頁面加載一個帶有子類別的內容,但主要類別消失。顯示子類別頁面中的主要類別Woocommerce

例子:我有這樣

Menu 1 Menu 2 Menu 3 

菜單當我點擊菜單1我得到這樣的:

Submenu 1 

我想實現的是,當我點擊菜單1我想得到這個:

Menu 1 Menu 2 Menu 3 

Submenu 1 

的woocommerce.php看起來是這樣的:

$parentid = get_queried_object_id(); 
       $args = array(
        'number'  => $number, 
        'orderby' => $orderby, 
        'order'  => $order, 
        'hide_empty' => $hide_empty, 
        'include' => $ids, 
        'parent' => $parentid 

       ); 
       $product_categories = get_terms('product_cat', $args); 
       $current_cat = $wp_query->query['product_cat']; 
       echo '<ul class="product_cats">'; 
       foreach ($product_categories as $category) { 
        if($category->slug == $current_cat) { 
         $active_class = 'class="active"'; 
        } else { 
         $active_class = null; 
        } 
        echo '<li><a '. $active_class .' href="'. 
        get_term_link($category) .'">'. $category->name .'</a></li>'; 

       } 
       echo '</ul>'; 

請幫我

回答

0
$all_categories = get_categories($args); 
echo "<div class='container'>"; 
    echo "<div class='productsubmenu'>"; 
echo "<ul>"; 

foreach ($all_categories as $cat) 
{ 
    if($text!="shop") 
      { 
       if($string==$cat->name) 
       { 
       //echo "hello";exit; 
       $my= "active"; 
       } 
       else 
       { 
       $my=""; 
       } 
      } 

if($cat->category_parent == 0) 
{ 
$category_id = $cat->term_id; 
$thumbnail_id = get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true); 
$image = wp_get_attachment_url($thumbnail_id); 
echo '<li class="'.$my.'"><a href="'.get_term_link($cat) . '">'.$cat->name.'</a>'; 
$args2 = array(
'taxonomy' => $taxonomy, 
'child_of' => 0, 
'parent' => $category_id, 
'orderby' => $orderby, 
'show_count' => $show_count, 
'pad_counts' => $pad_counts, 
'hierarchical' => $hierarchical, 
'title_li' => $title, 
'hide_empty' => $empty 

); 

$sub_cats = get_categories($args2); 
if($sub_cats) 
{ 
foreach($sub_cats as $sub_category) 
{ 
    if($text!="shop") 
      { 
       if($slug==$sub_category->cat_name) 
       { 
       //echo "hello";exit; 
       $my= "active"; 
       } 
       else 
       { 
       $my=""; 
       } 
      } 
echo "<ul class='subcategory'>"; 

if($sub_cats->$sub_category == 0) 
{ 
echo '<li class="'.$my.'"><a href="'.get_term_link($sub_category) . '">'.$sub_category->cat_name; 
echo "</a></li>"; 

} 

} 
echo "</ul>"; 
} 

echo "</li>"; 
} 
else 
{ 

} 
} 

echo "</ul>"; 
echo "</div>"; 
echo "</div>"; 
相關問題