advantage_bootstrap_walker

Functions for Bootstrap Framework.

Defined (1)

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

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