Custom Walker Menu showing Menu as Select Style

In functions.php

class Walker_Nav_Menu_Oudarya extends Walker_Nav_Menu {
function start_lvl(&$output, $depth){
$indent = str_repeat(“\t”, $depth); // don’t output children opening tag (`<ul>`)
}
function end_lvl(&$output, $depth){
$indent = str_repeat(“\t”, $depth); // don’t output children closing tag
}
/**
* Start the element output.
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. May be used for padding.
* @param array $args Additional strings.
* @return void
*/
function start_el(&$output, $item, $depth, $args) {
//print_r($item);
$url = ‘#’ !== $item->url ? $item->url : ”;
$output .= ‘<option id=”‘.$item->title.'” value=”‘ . $url . ‘”>’ . $item->title;
}
function end_el(&$output, $item, $depth){
$output .= “</option>\n”; // replace closing </li> with the option tag
}
}

In front-end

<?php
/* wp_nav_menu(array(
‘theme_location’ => ‘shopmobile’, // your theme location here
‘walker’         => new Walker_Nav_Menu_Oudarya(),
‘items_wrap’     => ‘<select onchange=”myFunction()” name=”main_navigation” id=”main_navigation” class=”fl”>%3$s</select>’,
)); */
?>

/* window.document.onload = function(e){

document.getElementById(“food”).setAttribute(‘selected’,’selected’);

}
function myFunction() {
var x = document.getElementById(“main_navigation”).value;
//alert(x);
jQuery(location).attr(‘href’,x);
} */

Advertisements

Published by

oudarya

I am a developer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s