OHIDUL951

Walker Class - Mega Menu

May 1st, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. <?php
  2.  
  3. class Shape_Nav_Menu_Walker extends Walker_Nav_Menu {
  4.     function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
  5.         global $wp_query;
  6.         $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  7.  
  8.         global $wp_query;    
  9.        
  10.         $class_names = $value = '';
  11.  
  12.         $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  13.        
  14.         // if its the mega menu
  15.         if( $item->object == 'mega_menu' ) {
  16.             $classes[] = 'mega-par';
  17.         }
  18.  
  19.         $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  20.         $class_names = ' class="' . esc_attr( $class_names ) . '"';
  21.  
  22.         $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
  23.  
  24.         $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
  25.         $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
  26.         $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
  27.         $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
  28.  
  29.         $item_output = $args->before;
  30.         $item_output .= '<a'. $attributes .'>';
  31.         $item_output .= $args->link_before . do_shortcode(  apply_filters( 'the_title', $item->title, $item->ID )) . $args->link_after;
  32.         $item_output .= '<span class="sub">' . do_shortcode( $item->description ) . '</span>';
  33.         $item_output .= '</a>';
  34.         $item_output .= $args->after;
  35.  
  36.         if( $item->object == 'mega_menu' ) {
  37.            
  38.             $getPost = get_post($item->object_id);
  39.             $item_output .= '<ul class="shape-mega-menu custom_mega_menu">'. do_shortcode( $getPost->post_content    ) .'</ul>';
  40.  
  41.             $shortcodes_custom_css = get_post_meta( $getPost->ID, '_wpb_shortcodes_custom_css', true );
  42.             if ( ! empty( $shortcodes_custom_css ) ) {
  43.                 echo '<style type="text/css" data-type="vc_shortcodes-custom-css">';
  44.                 echo $shortcodes_custom_css;
  45.                 echo '</style>';
  46.             }
  47.            
  48.             $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );        
  49.         } else {
  50.             $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );        
  51.         }
  52.  
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment