When I use this code below

<?php wp_nav_menu( array('menu' => 'categories' )); ?>

I can make a new menu to list up for example alle categories in wordpress I created. I use it to list up all the categories in the middle of the page.

My question now: Is there an easy way to make a dropdown menu for every subcategory that exists? So when I click on a specific category its subcategories are showing up?

1 Answer 1


This will give you your desired result.


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

foreach ($list_categories as $cat)

if($cat->category_parent == 0)
$category_id = $cat->term_id;

echo '<li class="parent '.$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

$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 1,
'parent' => $parent_cat_ID,
'taxonomy' => 'product_cat'
$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>';

echo '</ul>';
echo "</li>";

  • Thanks for your quick response. Do I need the Woocommerce plugin for this? A couple of variables are not defined and the else and brackets at the end doesn't make sence for me. It is not working unfortunately.
    – Martin
    Feb 21, 2018 at 17:51
  • verry sorry martin i was in hurry i edited and tested code it's working now. Feb 22, 2018 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.