Advertisement
Guest User

RainbowThemes Responsive Menu

a guest
May 19th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <?php
  2.  
  3. class Mt_Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu {
  4.  
  5.     private $closed = true;
  6.    
  7.     function start_lvl(&$output, $depth) {
  8.         $indent = str_repeat("\t", $depth); // don't output children opening tag (`<ul>`)
  9.     }
  10.  
  11.     function end_lvl(&$output, $depth) {
  12.         $indent = str_repeat("\t", $depth); // don't output children closing tag
  13.     }
  14.  
  15.     function start_el(&$output, $item, $depth, $args) {
  16.        
  17.         if( !$this->closed ) {
  18.             $output .= "</option>\n";
  19.             $this->closed = true;
  20.         }
  21.        
  22.         // add spacing to the title based on the depth
  23.         $item->title = str_repeat("&nbsp;", $depth * 4) . $item->title;
  24.  
  25.         parent::start_el(&$output, $item, $depth, $args);
  26.  
  27.         // no point redefining this method too, we just replace the li tag...
  28.         $output = str_replace('<li', '<option', $output);
  29.         $output = str_replace('</a>', '', $output);
  30.         $output = preg_replace('/><a href="(.*?)">/', ' value="\\1">', $output);
  31.         $output = preg_replace('/class="(.*?) current-menu-item(.*?)"/', 'selected="selected"', $output);
  32.         $output = preg_replace('/ class="(.*?)"/', '', $output);
  33.        
  34.         $this->closed = false;
  35.     }
  36.  
  37.     function end_el(&$output, $item, $depth) {
  38.     }
  39.  
  40. }
  41.  
  42.  
  43.  
  44. // usage
  45.  
  46. wp_nav_menu(array(
  47.     'container_class' => 'mt-responsive-menu',
  48.     'theme_location' => 'primary',
  49.     'walker' => new Mt_Walker_Nav_Menu_Dropdown(),
  50.     'items_wrap' => '<select><option value="#">'. __('Navigate to...', 'mt') .'</option>%3$s</option></select>'
  51. ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement