nish01

Functions.php

May 2nd, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.15 KB | None | 0 0
  1. // Menu output mods
  2. class description_walker extends Walker_Nav_Menu
  3. {
  4.       function start_el(&$output, $item, $depth, $args)
  5.       {
  6.             global $wp_query;
  7.             $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  8.            
  9.             $class_names = $value = '';
  10.            
  11.             // If the item has children, add the dropdown class for bootstrap
  12.             if ( $args->has_children ) {
  13.                 $class_names = "dropdown ";
  14.             }
  15.            
  16.             $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  17.            
  18.             $class_names .= join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  19.             $class_names = ' class="'. esc_attr( $class_names ) . '"';
  20.            
  21.             $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
  22.  
  23.             $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
  24.             $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
  25.             $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
  26.             $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
  27.             // if the item has children add these two attributes to the anchor tag
  28.             if ( $args->has_children ) {
  29.                 //$attributes .= ' class="dropdown-toggle" data-toggle="dropdown"';
  30.                 $attributes .= ' ';
  31.             }
  32.  
  33.             $item_output = $args->before;
  34.             $item_output .= '<a'. $attributes .'>';
  35.             $item_output .= $args->link_before .apply_filters( 'the_title', $item->title, $item->ID );
  36.             $item_output .= $args->link_after;
  37.             // if the item has children add the caret just before closing the anchor tag
  38.             if ( $args->has_children ) {
  39.                 $item_output .= '<b class="caret"></b></a>';
  40.             }
  41.             else{
  42.                 $item_output .= '</a>';
  43.             }
  44.             $item_output .= $args->after;
  45.  
  46.             $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  47.             }
  48.            
  49.         function start_lvl(&$output, $depth) {
  50.             $indent = str_repeat("\t", $depth);
  51.             $output .= "\n$indent<ul class=\"dropdown-menu\">\n";
  52.         }
  53.            
  54.         function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output )
  55.             {
  56.                 $id_field = $this->db_fields['id'];
  57.                 if ( is_object( $args[0] ) ) {
  58.                     $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
  59.                 }
  60.                 return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
  61.             }
  62.        
  63.            
  64. }
  65.  
  66. add_editor_style('editor-style.css');
  67.  
  68. // Add Twitter Bootstrap's standard 'active' class name to the active nav link item
  69.  
  70. add_filter('nav_menu_css_class', 'add_active_class', 10, 2 );
  71. function add_active_class($classes, $item) {
  72.     if($item->menu_item_parent == 0 && in_array('current-menu-item', $classes)) {
  73.         $classes[] = "active";
  74.     }
  75.     return $classes;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment