此代码显示所有可用类别,以及在其相应父类别的正下方列出的子类别。是否可以制作一个嵌套菜单,以便当我单击父类别时,子类别在父类别的正下方向下滚动/下拉?
$args = array(
\'child_of\' => 0,
\'current_category\' => 0,
\'depth\' => 0,
\'echo\' => 1,
\'exclude\' => \'\',
\'exclude_tree\' => \'\',
\'feed\' => \'\',
\'feed_image\' => \'\',
\'feed_type\' => \'\',
\'hide_empty\' => 0,
\'hide_title_if_empty\' => false,
\'hierarchical\' => true,
\'order\' => \'ASC\',
\'orderby\' => \'name\',
\'separator\' => \'<br />\',
\'show_count\' => 0,
\'show_option_all\' => \'\',
\'show_option_none\' => __( \'No categories\' ),
\'style\' => \'list\',
\'taxonomy\' => \'category\',
\'title_li\' => __( \'Categories\' ),
\'use_desc_for_title\' => 1,
);
$list_categories = get_categories( $args );
echo "<div class=\'container\'>";
echo "<div class=\'productsubmenu\'>";
echo "<ul>";
foreach( $list_categories as $cat ) {
$cat_id = $cat->term_id;
$args2 = array(
\'child_of\' => $cat_id,
\'current_category\' => 0,
\'depth\' => 0,
\'echo\' => 1,
\'exclude\' => \'\',
\'exclude_tree\' => \'\',
\'feed\' => \'\',
\'feed_image\' => \'\',
\'feed_type\' => \'\',
\'hide_empty\' => 0,
\'hide_title_if_empty\' => false,
\'hierarchical\' => true,
\'order\' => \'ASC\',
\'orderby\' => \'name\',
\'separator\' => \'<br />\',
\'show_count\' => 0,
\'show_option_all\' => \'\',
\'show_option_none\' => __( \'No categories\' ),
\'style\' => \'list\',
\'taxonomy\' => \'category\',
\'title_li\' => __( \'Categories\' ),
\'use_desc_for_title\' => 1,
);
if( $cat->category_parent == 0 ) {
$category_id = $cat->term_id;
echo \'<li class="parentss"><a href="\'.get_term_link( $cat ) . \'">\' . $cat->name . \'</a>\';
$subcats = get_categories( $args2 );
echo \'<ul class="wooc_sclist">\';
foreach( $subcats as $sc ) {
$link = get_term_link( $sc->slug, $sc->taxonomy );
echo \'<li class="" ><a href="\'. $link .\'">\'.$sc->name.\'</a></li>\';
var_dump( cat_is_ancestor_of($cat_id,32));
var_dump( $cat_id);
}
}
echo \'</ul>\';
echo "</li>";
}