Alexander Kirwan
Alexander Kirwan

Reputation: 25

Walker class not found error

Hi I am using wordpress for the first time. I am trying to incorperated the walker class into my project which is located at

D:\wamp\www\SgsOnline\wp-content\themes\storefront\inc\functions\walker.php

I've included my class in my functions as

require get_template_directory() . '/inc/functions/walker.php';

And I am trying to call it in my header like :

	function storefront_primary_navigation() {
		?>
		<nav id="site-navigation" class="main-navigation " role="navigation" aria-label="<?php esc_html_e( 'Primary Navigation', 'storefront' ); ?>">
		<button class="menu-toggle" aria-controls="primary-navigation" aria-expanded="false"><?php echo esc_attr( apply_filters( 'storefront_menu_toggle_text', __( 'Navigation', 'storefront' ) ) ); ?></button>
			<?php
			wp_nav_menu(
				array(
					'theme_location'	=> 'primary',
					'container_class'	=> 'primary-navigation',
					'menu_class'=>'nav navbar-nav navbar-left nav-tabs',
					'walker' => new Walker_Nav_Primary()
					)
			);
			?>
		</nav><!-- #site-navigation -->
		<?php
	}

But I am getting a error :

Fatal error: Class 'Walker_Nav_Primary' not found in D:\wamp\www\SgsOnline\wp-content\themes\storefront\inc\structure\header.php on line 65

This is oblivious wrong because it is looking in the wrong place for the class. If anyone has any experience with this would be great

Regards

UPDATE

here is the class code

<?php 
/* Collection of walker classes*/
class Walker_Nav_Primary extends Walker_Nav_menu {

	function start_lvl( &$output, $depth){ //ul
		$indent = str_repeat("\t", $depth );
		$submenu = ($depth > 0) 'sub-menu' : ''; //Detect if the lvls is a submenu
		$output .= "\n$indent<ul class=\"dropdown-menu$submenu depth_$depth\">\n";
	}


/*
	function end_lvl(){ // close ul

	}



	Not used at the moment 

	function start_el(){ // li, a, span

	}

	function end_el(){ // closing  li, a, span

	}
*/

}

Upvotes: 0

Views: 4203

Answers (2)

Simon Pollard
Simon Pollard

Reputation: 2588

I believe the issue is how you reference your walker...

'walker' => new Walker_Nav_Primary()

should just be...

'walker' => new Walker_Nav_Primary

no () needed.

If there was an issue with how you include your walker.php file that would error first as functions.php is run before your header.php.

Upvotes: 0

Kaspars Primaks
Kaspars Primaks

Reputation: 82

At first glance it appears that file path is incorrect. / is unix directory separator but you need to use \ for Windows.

$path_elements = array(get_template_directory(), 'inc', 'functions', 'walker.php');
require join(DIRECTORY_SEPARATOR , $path_elements);

Walker_Nav_Primary has a syntax error in shorthand if-else statement (missing question mark after logical expression).

$submenu = ($depth > 0) ? 'sub-menu' : '';

Upvotes: 1

Related Questions