Show Certain Sidebar Widget Menu Depending On What Page You Are On

Hi

I have created 5 sidebars where I need to add specified menus. I have created a custom template to show the sidebar.

I need the ability to show a certain sidebar menu if the users is on for example any pages under the parent category ‘tenants’ and if the user is on pages under the parent category ‘office space’ show the office space menu sidebar.

I understand this is done by if/else statements? But no idea what I need to add to get this to work.

I would really appreciate any help you might be able to offer me please.

Many Thanks

I’m assuming that you know how to get the parent category of the page in question. If you don’t, let us know, and we can backtrack to that.

I’m not sure how you have the menus set up - but here is what I would do using wp_nav_menu(). I use a switch statement to match the category slug with the menu name (you fill in your own category slugs in this example):

switch($cat_slug) {
	case 'cat-one ' : 
		$cat_menu = 'menu-one';
		break;
	case 'cat-two ' : 
		$cat_menu = 'menu-two';
		break;
	case 'cat-three ' : 
		$cat_menu = 'menu-three';
		break;
}

$nav_args = array(
	'menu' => $cat_menu
);

wp_nav_menu($nav_args);

Thats great, many thanks, I will try it out and get back to you if I come across any problems.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.