• Can someone help me see what am I doing wrong I am trying to use the nav walker to wrap one container around a certain group of submenu below is the menu structure.

    -Test
    –Subtest <— Looking to only wrap the container around this levels children
    —Subsubtest
    —Subsubtest 2
    –Subtest 2
    -Test 2
    –Subtest <— Looking to only wrap the container around this levels children
    — Subsubtest
    -Test 3

    So anything that has both parent and children.

    
    <pre><code>class OBE_Mega_Sub_Menu extends Walker_Nav_Menu
    {
        function start_lvl( &$output, $depth = 0, $args = array() ) {
            $indent = str_repeat(&quot;\t&quot;, $depth);
    		// $classes = $args->
    		$link_depth = $args->depth;
    		if($args->walker->depth && $depth == 1) {
    			$output .= &quot;\n$indent<div class='container'><div class='sub-menu-holder flex flex-column'>\n&quot;;
    		} else {
    			$output .= &quot;\n$indent<ul class='sub-menu' data-slide><div class='container $depth $link_depth'><div class='sub-menu-holder'>\n&quot;;
    		}
           
        }
        function end_lvl( &$output, $depth = 0, $args = array() ) {
            $indent = str_repeat(&quot;\t&quot;, $depth);
    		$link_depth = $args->depth;
    		if($args->walker->depth && $depth == 1) {
    			$output .= &quot;$indent</div></div>\n&quot;;
    		} else {
    			$output .= &quot;$indent</div></div></ul>\n&quot;;
    		}
            
        }
    }
    
    </code></pre>

    I’ve tried a few combinations but it always goes to the else.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Hi there,

    When you say combinations, what do you mean by that?

    Thread Starter shuangmiles

    (@shuangmiles)

    I’ve tried different conditions in the if statement here

    
    if($args->walker->has_children && $depth == 1) {
    			$output .= &quot;$indent</div></div>\n&quot;;
    		} else {
    			$output .= &quot;$indent</div></div></ul>\n&quot;;
    		}
    Thread Starter shuangmiles

    (@shuangmiles)

    What I am trying to ask is for start_lvl and end_lvl how can you tell if the menu item has children but is not the top level? what condition with the params that the functions have can determine this?

    Moderator bcworkz

    (@bcworkz)

    The depth arg is a directive for how deep the menu should go, not where it is currently. I think you need to look at the current item’s immediate parent object’s parent. If it is 0, then the current object is the first child level.

    Alternately, use get_ancestors() and count the elements returned. Should only be the one parent.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Looking to use walker to give a specific container to a submenu’ is closed to new replies.