Advertisement
cybershot

custom walker

Feb 14th, 2013
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.79 KB | None | 0 0
  1. class Amaranthe_Custom_Walker_Nav_Sub_Menu extends Walker_Nav_Menu {
  2.  
  3. // add classes to ul sub-menus
  4. function start_lvl( &$output, $depth ) {
  5.     // depth dependent classes
  6.     $indent = ( $depth > 0  ? str_repeat( "\t", $depth ) : '' ); // code indent
  7.     $display_depth = ( $depth + 1); // because it counts the first submenu as 0
  8.     $classes = array(
  9.         'sub-menu',
  10.         ( $display_depth % 2  ? 'menu-odd' : 'menu-even' ),
  11.         ( $display_depth >=2 ? 'sub-sub-menu' : '' ),
  12.         'menu-depth-' . $display_depth
  13.         );
  14.     $class_names = implode( ' ', $classes );
  15.  
  16.     // build html
  17.     $output .= "\n" . $indent . '<div class="submenu"><ul class="' . $class_names . '">' . "\n";
  18. }
  19.  
  20. // add main/sub classes to li's and links
  21.  function start_el( &$output, $item, $depth, $args ) {
  22.     global $wp_query;
  23.     $indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent
  24.  
  25.     // depth dependent classes
  26.     $depth_classes = array(
  27.         ( $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ),
  28.         ( $depth >=2 ? 'sub-sub-menu-item' : '' ),
  29.         ( $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ),
  30.         'menu-item-depth-' . $depth
  31.     );
  32.         if( $depth == 0 ){
  33.         $output .= '<li class="markers"></li>';
  34.     }
  35.     $depth_class_names = esc_attr( implode( ' ', $depth_classes ) );
  36.  
  37.     // passed classes
  38.     $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  39.     $class_names = esc_attr( implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ) );
  40.  
  41.     // build html
  42.     $output .= $indent . '<li id="nav-menu-item-'. $item->ID . '" class="' . $depth_class_names . ' ' . $class_names . '">';
  43.     $temp_url = strtolower(trim(str_replace(" ", "_", $item->title)));
  44.     $item->url = "#!/page_".$temp_url;
  45.    
  46.     if( $depth > 0 ){
  47.         $item->title = '<p>'.$item->title.'</p>';
  48.     }
  49.    
  50.      //link attributes
  51.     $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
  52.     $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
  53.     $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
  54.     $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
  55.     $attributes .= ' class="menu-link ' . ( $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ) . '"';
  56.  
  57.     $item_output = sprintf( '%1$s<a%2$s>%3$s%4$s%5$s</a>%6$s',
  58.         $args->before,
  59.         $attributes,
  60.         $args->link_before,
  61.         apply_filters( 'the_title', $item->title, $item->ID ),
  62.         $args->link_after,
  63.         $args->after
  64.     );
  65.  
  66.        
  67.  
  68.     // build html
  69.     $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement