A custom WordPress nav walker class to fully implement the Twitter Bootstrap 4.0+ navigation style (v3-branch available for Bootstrap 3) in a custom theme using the WordPress built in menu manager.
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.
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 ]);
}
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;
I feel like you either found a solution by now or moved on to something else. Either way this is not something that core bootstrap supports and the navwalker aims to emulate core bootstrap behaviors only.
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
/**
/**
@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;
} $item_output .= '>'; $item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after; $item_output .= ''; $item_output .= $args->after;
$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args); }
/**
@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); }
/**
@param array $args passed from the wp_nav_menu function. */ public static function fallback($args) { if (current_user_can('manage_options')) { $fb_output = null;
} }`