• In trying to build 2 linked menus, lets say the hierarchy is like this (In the menu options)

    - A
         -- B
         -- C
         -- D
           -- D1
           -- D2
    - A1

    The first menu I want it to be fixed so I fetched it with
    ‘depth’ => 1, .

    And the second menu has to be change according the first menu (like if I press A it will show B and C AND D only
    and when I press B its still has to get open as B, C, D (same if I press D1). I think we got the point of how it should work.
    As I tried to build this, I only accoplishe to fetch the menu only when you choice from the main menu (Like A or A1).
    but as you choice deeper in the depth menu its showing hi’s childrens. (like if I choice D the sub-menu gets to be D1 and D2) and I dont want it,
    I tried to check in which depth the menu is, or get anything that will help me make this sort but I couldn’t find anything.

    here is some code:
    the function:

    function submenu_get_children_ids( $id, $items ) {
    
            $ids = wp_filter_object_list( $items, array( 'menu_item_parent' => $id ), 'and', 'ID' );
    
            foreach ( $ids as $id ) {
    
                $ids = array_merge( $ids, submenu_get_children_ids( $id, $items ) );
            }
    
            return $ids;
        }

    fetching the menu :

    $menu = wp_nav_menu(array(
        	'container' => false,                           // remove nav container
        	'container_class' => 'right_menu',                 // class of container (should you choose to use it)
        	'menu' => __( 'top_main_nav', 'bonestheme' ),  // nav name
        	'menu_class' => 'main_bar_menu '.$lang.'',               // adding custom nav class
        	'theme_location' => 'main-nav',                 // where it's located in the theme
        	'before' => '',                                 // before the menu
        	'after' => '',                                  // after the menu
        	'link_before' => '',                            // before each link
        	'link_after' => '',                             // after each link
        	'depth' => 1,                                   // limit the depth of the nav
        	'fallback_cb' => ''                             // fallback function (if there is one)
        )); 
    
        $current_page = 0;
        // check if the current page has a menu.
    
        foreach(wp_get_nav_menu_items('top_main_nav') as $pagec) {
        	if(get_the_title() == $pagec->title) {
        		$current_page = $pagec->title;
        	}
        }
    
        if($current_page === 0) {
        	$current_page = "Home";
    
        }
    
        $args = array(
        	'container' => false,
        	'container_class' => 'main_bar_menu',
        	'menu'    => 'top_main_nav',
        	'menu_class' => 'main_bar_menu',
        	'submenu' => $current_page,
        );
        wp_nav_menu( $args );

    I’m trying to find a solution about 2 days now :\ if someone could guide me with that i’d be so thankful!

    thanks alot!

Viewing 1 replies (of 1 total)
  • you could create custom menus and a new widget area and have them display on different pages based on dynamic widgets.

Viewing 1 replies (of 1 total)
  • The topic ‘getting specific items from menu wordpress’ is closed to new replies.