Как вывести меню в виде select?

Нашел вот такой код

class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{

 //function start_el(&$output, $item, $depth, $args) {
    //function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
    // don't output children opening tag (`<ul>`)
    public function start_lvl(&$output, $depth = 0, $args = array()){}

    // don't output children closing tag    
    public function end_lvl(&$output, $depth = 0, $args = array()){}

    public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0){

      // add spacing to the title based on the current depth
      $item->title = str_repeat("&nbsp;", $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 = 0, $args = array()){
      $output .= "</option>\n";
    }
}

И добавил код для вызова меню

<?php
$args = array( // опции для вывода верхнего меню, чтобы они работали, меню должно быть создано в админке
'theme_location' => 'top', // идентификатор меню, определен в register_nav_menus() в function.php
'menu' => 'metro',
'walker'=> new Walker_Nav_Menu_Dropdown()
);
wp_nav_menu($args); // выводим верхнее меню
?>

Как заменить обвертку ul на select? Или может есть другой способ?


Ответы (0 шт):