Customer walker for creating JumpMenu
-
Hi, I’m trying to dynamically populate a JumpMenu using code I’ve found for a custom walker:
functions.php
class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{ // don't output children opening tag (<code><ul></code>) public function start_lvl(&$output, $depth){} // don't output children closing tag public function end_lvl(&$output, $depth){} public function start_el(&$output, $item, $depth, $args){ // add spacing to the title based on the current depth $item->title = str_repeat(" ", $depth * 4) . $item->title; // call the prototype and replace the <li> tag // from the generated markup... parent::start_el(&$output, $item, $depth, $args); $output = str_replace('<li', '<option', $output); } // replace closing </li> with the closing option tag public function end_el(&$output, $item, $depth){ $output .= "</option>\n"; } }In my theme:
<form name="form" id="form"> <select name="jumpMenu" id="jumpMenu1" onchange="MM_jumpMenu('parent',this,0)"> <option selected="selected">Choose a team</option> <?php wp_nav_menu(array( 'theme_location' => 'teams', // your theme location here 'walker' => new Walker_Nav_Menu_Dropdown(), 'items_wrap' => '<option>%3$s</option>', )); ?> </select> </form>This works on the homepage but not when you drill down to another sub-menu where the same menu appears. Also it won’t output the slug only the menu title. Is there any tweaks I can make to the code to make this happen?
Thanks
Darren
The topic ‘Customer walker for creating JumpMenu’ is closed to new replies.