Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

at present my custom walker works great :) but I can for the life of me get a 3rd level to appear...

I can get the top level and the 2nd level dropdown to show perfect, but how do I achieve a 3rd level.

Here is the custom walker I am using:

//bootstrap navigation
class bootWalker extends Walker_Nav_Menu {
    function check_current( $classes ) {
        return preg_match('/(current[-_])|active|dropdown/', $classes);
    }

    function start_lvl( &$output, $depth = 0, $args = array() ) {
        $output .= "\n<ul class=\"dropdown-menu\">\n";
    }

    function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
        $item_html = '';
        parent::start_el($item_html, $item, $depth, $args);

        if( $item->is_dropdown && ($depth === 0) ) {
            $item_html = str_replace('<a', '<a class="dropdown-toggle" data-toggle="dropdown" data-target="'.esc_attr($item->url).'"', $item_html);
        }

        elseif( stristr($item_html, 'li class="divider') ) {
            $item_html = preg_replace('/<a[^>]*>.*?<\/a>/iU', '', $item_html);
        }
        elseif( stristr($item_html, 'li class="nav-header') ) {
            $item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '$1', $item_html);
        }

        if($depth === 0){
            $item_html = str_replace('current_page_item', 'active', $item_html);
        }

        $output .= $item_html;
    }

    function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) {
        $element->is_dropdown = !empty( $children_elements[$element->ID] );

        if( $element->is_dropdown ) {
            if( $depth === 0 ) {
                $element->classes[] = 'dropdown';
            }
        }

        parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
    }
}

I then call it in within the header using the following:

<nav id="main_menu">
    <div class="nav-collapse collapse">
    <?php
    if( has_nav_menu( 'primary' ) ) {
       wp_nav_menu( array( 'theme_location' => 'primary', 'container' => false, 'menu_class' => 'nav nav-pills', 'depth' => 3, 'walker' => new bootWalker() ) );
    }
    ?>
    </div>
 </nav>

Could anyone put me out of my misery, been trying for a few days now :(

Thanks

share|improve this question
    
Where is youre end_lvl() method? Encapsulating opening and closing tags for individual items in start_el() is perfectly fine, but if you aren't providing an end_lvl() method to close your tags at the branch level, then the resulting <ul> elements won't be properly closed out. –  Matt Van Andel Feb 18 at 22:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.