Quantcast
Viewing all articles
Browse latest Browse all 8245

charlyanderson on "Add additional menu"

I ALWAYS struggle with WP Menu's, just can't get my head around them....

I am working on a theme that only supports one menu so I need to add an additional menu.

The menu code is:-

<?php $args = array('container' => 'nav','container_class' => 'sidemenu','walker'=>new ows_walker_nav_menu); ?>
<?php wp_nav_menu($args); ?>

Function code:-

/* ========================================================================================================================

	Register Navigation

	======================================================================================================================== */
register_nav_menu('main', 'Main navigation menu');
class ows_walker_nav_menu extends Walker_Nav_Menu {

	// add classes to ul sub-menus
	function start_lvl( &$output, $depth ) {
	    // depth dependent classes
	    $indent = ( $depth > 0  ? str_repeat( "\t", $depth ) : '' ); // code indent
	    $display_depth = ( $depth + 1); // because it counts the first submenu as 0
	    $classes = array(
	        'sub-menu',
	        ( $display_depth % 2  ? 'menu-odd' : 'menu-even' ),
	        ( $display_depth >=2 ? 'sub-sub-menu' : '' ),
	        'menu-depth-' . $display_depth
	        );
	    $class_names = implode( ' ', $classes );

	    // build html
	    if ($display_depth >= 1) {
	    	$output .= '<nav class="sub-menu-container">' . "\n";
	    }
	    $output .= "\n" . $indent . '<ul class="' . $class_names . '">' . "\n";
	}

	function end_lvl( &$output, $depth ) {
    // depth dependent classes
    $indent = ( $depth > 0  ? str_repeat( "\t", $depth ) : '' );
    $display_depth = ( $depth + 1); // because it counts the first submenu as 0
    $output .= "\n" . $indent . '</ul>' . "\n";
    if ($display_depth >= 1) {
    	$output .= '</nav>' . "\n";
    }
  }
}

I have tried to change this a few times but the theme either breaks or the change doesn't work. Could someone help me out and point me in the right direction please


Viewing all articles
Browse latest Browse all 8245

Trending Articles