最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme development - Show all menu levels except top level. How to exclude top level of a menu?

matteradmin10PV0评论

I have a menu that looks like this:

Women and Men har the top level menu items while the lower nagivation menu items are the children.

The menu structure looks like this:

Women
  New styles
  Clothes
    Jeans
    Dresses
    Shirts
  Underwear
Men
  New styles
  Clothes
    Jeans
    T-shirts
    Shirts
  Underwear

If I click on "Women", children of the Women menu item will be shown in the lower navigation. If I click on "Men", children of the Men menu item will be shown in the lower navigation.

Displaying the top level menu items (Women and Men) is easy. I'm doing it like this:

<?php wp_nav_menu(
    array(
        'theme_location' => 'main-menu', // Menu ID registered in functions.php
        'walker' => new Custom_Primary_Nav_Menu(),
        'depth' => '1', // Show levels. (0 = all)
        'container' => 'nav', // What container element to wrap the nav with
        'fallback_cb' => false // If the menu doesn't exists, the navigation will fall back to 'wp_page_menu'
    )
); ?>

However displaying the children are not so easy. The 'depth' parameter is not enough.

I need to display menu items from 2nd level to infinity thereby excluding the top level items.

How can I do this?

I wan't to use only 1 menu for everything if possible so that it's easy to show a mobile navigation with everything in it.

Post a comment

comment list (0)

  1. No comments so far