Bootstrap_Navbar_Nav_Walker

The Eewee responsive design Bootstrap Navbar Nav Walker class.

Defined (1)

The class is defined in the following location(s).

/functions.php  
  1. class Bootstrap_Navbar_Nav_Walker extends Walker_Nav_Menu { 
  2. function check_current($val) { 
  3. return preg_match('/(current-)|active|dropdown/', $val); 
  4.  
  5. function start_lvl(&$output, $depth) { 
  6. $output .= "\n<ul class=\"dropdown-menu\">\n"; 
  7.  
  8. function start_el(&$output, $item, $depth, $args) { 
  9. global $wp_query; 
  10. $indent = ($depth) ? str_repeat("\t", $depth) : ''; 
  11.  
  12. $slug = sanitize_title($item->title); 
  13. $id = apply_filters('nav_menu_item_id', 'menu-' . $slug, $item, $args); 
  14. $id = strlen($id) ? '' . esc_attr( $id ) . '' : ''; 
  15.  
  16. $li_attributes = ''; 
  17. $class_names = $value = ''; 
  18.  
  19. $classes = empty($item->classes) ? array() : (array) $item->classes; 
  20. if ($args->has_children) { 
  21. $classes[] = 'dropdown'; 
  22. $li_attributes .= ' data-dropdown="dropdown"'; 
  23. $classes[] = ($item->current) ? 'active' : ''; 
  24. $classes = array_filter($classes, array(&$this, 'check_current')); 
  25.  
  26. $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item)); 
  27. $class_names = $class_names ? ' class="' . $id . ' ' . esc_attr($class_names) . '"' : ' class="' . $id . '"'; 
  28.  
  29. $output .= $indent . '<li' . $class_names . $li_attributes . '>'; 
  30.  
  31. $attributes = ! empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) .'"' : ''; 
  32. $attributes .= ! empty($item->target) ? ' target="' . esc_attr($item->target ) .'"' : ''; 
  33. $attributes .= ! empty($item->xfn) ? ' rel="' . esc_attr($item->xfn ) .'"' : ''; 
  34. $attributes .= ! empty($item->url) ? ' href="' . esc_attr($item->url ) .'"' : ''; 
  35. $attributes .= ($args->has_children) ? ' class="dropdown-toggle" data-toggle="dropdown"' : ''; 
  36.  
  37. $item_output = $args->before; 
  38. $item_output .= '<a'. $attributes .'>'; 
  39. $item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after; 
  40. $item_output .= ($args->has_children) ? ' <b class="caret"></b>' : ''; 
  41. $item_output .= '</a>'; 
  42. $item_output .= $args->after; 
  43.  
  44. $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); 
  45. function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) { 
  46. if (!$element) { return; } 
  47.  
  48. $id_field = $this->db_fields['id']; 
  49.  
  50. // display this element 
  51. if (is_array($args[0])) { 
  52. $args[0]['has_children'] = !empty($children_elements[$element->$id_field]); 
  53. } elseif (is_object($args[0])) { 
  54. $args[0]->has_children = !empty($children_elements[$element->$id_field]); 
  55. $cb_args = array_merge(array(&$output, $element, $depth), $args); 
  56. call_user_func_array(array(&$this, 'start_el'), $cb_args); 
  57.  
  58. $id = $element->$id_field; 
  59.  
  60. // descend only when the depth is right and there are childrens for this element 
  61. if (($max_depth == 0 || $max_depth > $depth+1) && isset($children_elements[$id])) { 
  62. foreach ($children_elements[$id] as $child) { 
  63. if (!isset($newlevel)) { 
  64. $newlevel = true; 
  65. // start the child delimiter 
  66. $cb_args = array_merge(array(&$output, $depth), $args); 
  67. call_user_func_array(array(&$this, 'start_lvl'), $cb_args); 
  68. $this->display_element($child, $children_elements, $max_depth, $depth + 1, $args, $output); 
  69. unset($children_elements[$id]); 
  70.  
  71. if (isset($newlevel) && $newlevel) { 
  72. // end the child delimiter 
  73. $cb_args = array_merge(array(&$output, $depth), $args); 
  74. call_user_func_array(array(&$this, 'end_lvl'), $cb_args); 
  75.  
  76. // end this element 
  77. $cb_args = array_merge(array(&$output, $element, $depth), $args); 
  78. call_user_func_array(array(&$this, 'end_el'), $cb_args);