0

I need some help customizing a walker function. I don't fully undrestand it, but it's helped me get half of what I need.

class themeslug_walker_nav_menu extends Walker_Nav_Menu {


    // add classes to ul sub-menus
    function start_lvl( &$output, $depth ) {
        // depth dependent classes
        $indent = ( $depth > 0  ? str_repeat( "\t", $depth ) : '' ); // code indent
        $display_depth = ( $depth + 1); // because it counts the first submenu as 0
        $classes = array(
            ' dropdown',
            /*?>( $display_depth % 4  ? ' ' : '' ),
            ( $display_depth >=4 ? '' : '' ),
            '-' . $display_depth<?php */
            );
        $class_names = implode( ' ', $classes );

        // build html
        $output .= "\n" . $indent . '<ul class="' . $class_names . '">' . "\n";
    }

}

Here is what I have so far, and it works great to add a submenu to the ul at the 2nd and third levels. I need to figure out how to add a custom class to the parent ul. I can do it in query but it's not quite the solution I would like. Any help is appreciated.

  • I need to figure out how to add a css class to an li that is a parent of a ul. I don't know what additional information you need? I am trying to use a walker class to do it. I can do it in Jquery but I need to try and have it through the nav class or the walker class. – user31344 Jul 7 '13 at 20:45
  • Walkers "walk" over the data generating markup as they go. They don't know what comes next, necessarily. Backtracking "up" a walker as it sounds like you need it tricky (I've done it once before, here) so I am trying to figure out if there is another way to do this. – s_ha_dum Jul 7 '13 at 21:05
  • Do the classes matter except to Javascript? – s_ha_dum Jul 7 '13 at 21:13
  • they initiate a dropdown (styling required) as well as some mobile stuff. I am basically building a theme that has the foundation framework integrated into it. – user31344 Jul 7 '13 at 21:15

Browse other questions tagged or ask your own question.