• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Wordpress

Wordpress World

  • Submit
  • Disclaimers
  • About
  • DMCA
  • Privacy Policy
  • Contact

You are here: Home / Nav walker: Display 3rd level items under 2nd level

Nav walker: Display 3rd level items under 2nd level

July 17, 2019 by

I am using the WP_navwalker for a dropdown menu. This works fine, but it only shows me the first and second level items. So de dropdown on the first level and a regular second item when dropdown is open. The third level is not visible. I want to display it under my second level items.

I am not skilled enough to properly edit the walker to fit make it fit my needs. can anyone help me?

The naw_walker code:

<?php /** * Menu Walker * * @see Walker::start_lvl() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param int    $depth Depth of page. Used for padding. * @param object $args Arguments. */ public function start_lvl(&$output, $depth = 0, $args = array()) { $indent = str_repeat("\t", $depth); $output .= "\n$indent<ul role=\"menu\" class=\" dvt-nav-dropdown closed\">\n"; } /** * Bootstrap Menu Walker start * * @see Walker::start_el() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int    $depth Depth of menu item. Used for padding. * @param object $args Arguments. * @param int    $id Menu item ID. */ public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { // Set level of indent. $indent = ($depth) ? str_repeat("\t", $depth) : ''; // Create nav menu item. $nav_menu_atts = array(); $nav_menu_atts['id'] = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args); $nav_menu_atts['class'] = empty($item->classes) ? array() : (array) $item->classes; $nav_menu_atts['class'] = apply_filters('nav_menu_css_class', $nav_menu_atts['class'], $item, $args); // Create link attributes. $nav_menu_link_atts = array(); $nav_menu_link_atts['title']  = ! empty($item->title)  ? $item->title  : ''; $nav_menu_link_atts['target'] = ! empty($item->target) ? $item->target : ''; $nav_menu_link_atts['rel']    = ! empty($item->xfn)    ? $item->xfn    : ''; // If item has_children add atts to a. $nav_menu_link_atts['href'] = $args->has_children && 0 === $depth ? '#' : (!empty($item->url) ? $item->url : ''); $nav_menu_link_atts = apply_filters('nav_menu_link_attributes', $nav_menu_link_atts, $item, $args); // Output LI menu item. $output .= $indent; $output .= '<li'; // Output menu attributes. foreach ($nav_menu_atts as $attr => $value) { // Output attribute name. $output .= ' ' . esc_attr($attr); if (!empty($value)) { $output .= '="'; // Add switch to handle escaping. switch ($attr) { case 'class': $output .= esc_attr(join(' ', array_filter($value))); break; default: $output .= esc_attr($value); break; } $output .= '"'; } } $output .= '>'; // Output A link. $item_output = $args->before; $item_output .= '<a'; // Output link attributes. foreach ($nav_menu_link_atts as $attr => $value) { if (!empty($value)) { // Output attribute name. $item_output .= ' ' . esc_attr($attr) . '="'; // Add switch to handle escaping. switch ($attr) { case 'href': $item_output .= esc_url($value); break; case 'class': $item_output .= esc_attr(join(' ', array_filter($value))); break; default: $item_output .= esc_attr($value); break; } $item_output .= '"'; } } $item_output .= '>'; $item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after; $item_output .= '</a>'; $item_output .= $args->after; $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); } /** * Traverse elements to create list from elements. * * Display one element if the element doesn't have any children otherwise, * display the element and its children. Will only traverse up to the max * depth and no ignore elements under that depth. * * This method shouldn't be called directly, use the walk() method instead. * * @see Walker::start_el() * @since 2.5.0 * * @param object $element Data object. * @param array  $children_elements List of elements to continue traversing. * @param int    $max_depth Max depth to traverse. * @param int    $depth Depth of current element. * @param array  $args Arguments. * @param string $output Passed by reference. Used to append additional content. * @return null Null on failure with no changes to parameters. */ public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) { if (! $element) { return; } $id_field = $this->db_fields['id']; // Display this element. if (is_object($args[0])) { $args[0]->has_children = ! empty($children_elements[ $element->$id_field ]); } parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); } /** * Menu Fallback * ============= * If this function is assigned to the wp_nav_menu's fallback_cb variable * and a manu has not been assigned to the theme location in the WordPress * menu manager the function with display nothing to a non-logged in user, * and will add a link to the WordPress menu manager if logged in as an admin. * * @param array $args passed from the wp_nav_menu function. */ public static function fallback($args) { if (current_user_can('manage_options')) { $fb_output = null; if ($args['container']) { echo '<' . esc_html($args['container']); if ($args['container_id']) { echo ' id="' . esc_attr($args['container_id']) . '"'; } if ($args['container_class']) { echo ' class="' . esc_attr($args['container_class']) . '"'; } echo '>'; } echo '<ul'; if ($args['menu_id']) { echo ' id="' . esc_attr($args['menu_id']) . '"'; } if ($args['menu_class']) { echo ' class="' . esc_attr($args['menu_class']) . '"'; } echo '>'; echo '</ul>'; if ($args['container']) { echo '</' . esc_html($args['container']) . '>'; } } } 

}

Sorry for my English, thanks in advance!


  • Thermaltake Level 10 Case Review
  • Level 3's strategy: Vision or folly?
  • Cell Phone Nav: The Next Big Thing
  • Apple MacBook Pro 13-Inch, Retina Display (2014)
  • Thermaltake Level 10
  • Antarctic ice cliffs WON’T collapse and suddenly trigger a dramatic rise in sea levels – they will dribble 'like honey' as they melt, claim scientists
  • Level Money (for iPhone)
  • Tim Walker explores dark corners of the V&A for 'Wonderful Things'
  • Find Your Way With a Big Display
  • Lenovo ThinkPad X1 Yoga (2nd Gen, OLED)

Filed Under: Tags 1st 2nd and 3rd degree burns, 1st 2nd 3rd world countries list, 1st 2nd 3rd form of verb with meaning, 2nd 3rd degree burns, 2nd 3rd shift jobs, 2nd 3rd grade math worksheets, difference between o level and a level, 2nd brigade 3rd infantry division

Primary Sidebar

RSS Recent Stories

  • Remove unwanted elements for a wp_nav_menu
  • Get_term_meta() always returns false
  • How to ask WordPress to generate XHTML?
  • Get user count based on multiple meta key values?
  • 21 Best Coffee Shop Themes for WordPress (2019)
Copyright © 2019 Wordpress. Power by Wordpress.