Last active
October 10, 2015 00:38
-
-
Save jaredatch/3604626 to your computer and use it in GitHub Desktop.
Dropdown menu walker class for mobile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Select dropdown menu walker class | |
* | |
* @since 1.0.0 | |
* @link http://jaredatchison.com/code/ | |
*/ | |
class ja_Mobile_Menu_Walker extends Walker_Nav_Menu{ | |
private $to_depth = -1; | |
/** | |
* Start level | |
* | |
* @since 1.0.0 | |
* @param string &$output | |
* @param int $depth | |
*/ | |
public function start_lvl( &$output, $depth ){ | |
$output .= '</option>'; | |
} | |
/** | |
* End level | |
* | |
* @since 1.0.0 | |
* @param string &$output | |
* @param nt $depth | |
*/ | |
public function end_lvl( &$output, $depth ){ | |
$indent = str_repeat( "\t", $depth ); | |
} | |
/** | |
* Start elements | |
* | |
* @since 1.0.0 | |
* @param string &$output | |
* @param array $item | |
* @param int $depth | |
* @param array $args | |
*/ | |
public function start_el( &$output, $item, $depth, $args ){ | |
$indent = ( $depth ) ? str_repeat( " ", $depth * 4 ) : ''; | |
$class_names = $value = ''; | |
$classes = empty( $item->classes ) ? array() : ( array ) $item->classes; | |
$classes[] = 'menu-item-' . $item->ID; | |
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); | |
$class_names = ' class="' . esc_attr( $class_names ) . '"'; | |
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args ); | |
$id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : ''; | |
$value = ' value="'. $item->url .'"'; | |
$output .= '<option' . $id. $value . $class_names . '>'; | |
$item_output = $args->before; | |
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; | |
$output .= $indent . $item_output; | |
} | |
/** | |
* End elements | |
* | |
* @since 1.0.0 | |
* @param string &$output | |
* @param array $item | |
* @param int $depth | |
*/ | |
public function end_el( &$output, $item, $depth ){ | |
if ( substr( $output, -9 ) != '</option>') | |
$output .= '</option>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment