Notice: Trying to get property of non-object in /var/www/wordpress/wp-content/themes/new-york-business/inc/icon-functions.php on line 72
Notice: Trying to get property of non-object in /var/www/wordpress/wp-includes/class-walker-nav-menu.php on line 227
Notice: Trying to get property of non-object in /var/www/wordpress/wp-includes/class-walker-nav-menu.php on line 229
Notice: Trying to get property of non-object in /var/www/wordpress/wp-includes/class-walker-nav-menu.php on line 229
Notice: Trying to get property of non-object in /var/www/wordpress/wp-includes/class-walker-nav-menu.php on line 231
Unfortunately, the site is in a localhost environment so cannot provide a functioning URL
]]>About
Services
– Risk Management
– Cleaning
– Benefits
– Claims Services
– Aviation
– Risk Optics
– Alarm
– Actuarial
Contact
Any suggestions
]]>BUT — I cannot figure out how to change the nav menu. Ideally it looks like this:
list pages/categories/etc as set up in “menus”
— if a page has subpages, change link to “>subpage title
I’m using the Walker setup to achieve two things:
#1 – Description
#2 – Formatting sub-nav
The formatting of the sub-nav is where my issue is. I’m attempting to create a multi-column sub navigation. I achieved this with the HTML site but I’m having a lot of trouble putting it into WordPress.
This is my function for the sub-nav
function start_lvl( &$output, $depth = 0, $args = array() )
{
$indent = str_repeat("\t", $depth);
$output .= "\n<div class=\"sub-nav\">\n";
$output .= "\n$indent<div class=\"menu-arro\"></div><div class=\"col_1\"><ul class=\"sub-menu\">\n";
}
function end_lvl( &$output, $depth = 0, $args = array() )
{
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul></div>\n".($depth ? "$indent</div>\n" : "");
}
This is how the HTML needs to be output.
<li><a href="#" class="drop">TITLE<br>
<span>Description</span></a>
<div class="sub-nav">
<div class="menu-arro"></div>
<div class="col_1">
<ul>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</div>
<div class="col_1">
<ul>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</div>
</div>
</li>
This is my call for the navigation itself
<?php $walker = new Menu_With_Description; ?>
<?php wp_nav_menu( array( 'menu' => 'Main', 'menu_class' => 'navigations', 'menu_id' => 'menu', 'walker' => $walker ) ); ?>
Now, what it’s doing for me is it’s displaying the “arrow”(which is just a CSS call), but not the actual UL columns, when viewing the source of the page it’s there but when hovering over the “Title”, it’s not actually displaying the col_1, ul/li outputs.
Am I coding something wrong on the Walker that I’m just completely missing?
The site is in development mode – https://174.132.146.250/~oct31st/contact/. Hover over “Cook”, there should be 3 clear columns there containing text but they’re not.
The nav is to mirror – https://marthastewart.com, if you hover over “Cook” you’ll see how it SHOULD be displaying (minus the featured posts on the side).
]]>In theme functions file:
class themeslug_walker_nav_menu extends Walker_Nav_Menu {
var $found_parents = array();
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
//this only works for second level sub navigations
$parent_item_id = 0;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';
#current_page_item
// Checks if the current element is in the current selection
if (strpos($class_names, 'current-menu-item')
|| strpos($class_names, 'current-menu-parent')
|| strpos($class_names, 'current-menu-ancestor')
|| (is_array($this->found_parents) && in_array( $item->menu_item_parent, $this->found_parents )) ) {
// Keep track of all selected parents
$this->found_parents[] = $item->ID;
//check if the item_parent matches the current item_parent
if($item->menu_item_parent!=$parent_item_id){
$output .= $indent . '<li' . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$item_output = $args->before;
$item_output .= '<a'. $attributes .'><div>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</div></a></li>';
$item_output .= $args->after;
}
//}
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
function end_el(&$output, $item, $depth) {
// Closes only the opened li
if ( is_array($this->found_parents) && in_array( $item->ID, $this->found_parents ) ) {
$output .= "";
}
}
function end_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
// If the sub-menu is empty, strip the opening tag, else closes it
if (substr($output, -22)=="<ul class=\"sub-menu\">\n") {
$output = substr($output, 0, strlen($output)-23);
} else {
$output .= "$indent</ul>\n";
}
}
}
To call the menu in my posts, I have this code:
<?php wp_nav_menu(array(
'container' => '',
'fallback_cb' => false,
'menu_class' => 'left-nav',
'theme_location' => 'header-menu',
'walker' => new themeslug_walker_nav_menu)
);
?>
Help please!
]]>