我有一个Woocommerce网站。在my.domain.com/shop我有一个显示所有类别的菜单。单击主类别时,页面将加载带子类别的内容,但主要类别将消失。
示例:我有一个这样的菜单
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 :(得分: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>";