Different menu on each page
-
I’ve been trying for days to pages to only show the menu from which the page was selected.
I tried using categories but if a page belongs to 2 categories both menus are displayed, which I don’t want.on the internet and have been trying to modify it to work. It is supposed to only display a menu if the term-id of the menu matches one I am checking for. It does this for only one menu, and all other menus after that doesn’t show. If I take out the (break) both menus show at the same time, instead of 1 at a time.
I know this is possible I just don’t know how to do it, please help.
<?php
$locations = get_registered_nav_menus();
$menus = wp_get_nav_menus();$menu_locations = get_nav_menu_locations();
$location_id = ”;
//if (isset($menu_locations[ $location_id ])) {
foreach ($menus as $menu) {
if($menu->term_id == $menu_locations[ ‘cats’]) {
// If the ID of this menu is the ID associated with the location we’re searching for
// This is the correct menu
// Get the items for this menu$menu_items = wp_get_nav_menu_items($menu);
// echo $menu_items;
get_template_part( ‘menu’, cats’ ); // Loads the menu-secondary.php template.
break;
}
if($menu->term_id == $menu_locations[ ‘dogs’]) {// This is the correct menu
// Get the items for this menu
$menu_items = wp_get_nav_menu_items($menu);
// echo $menu_items;
get_template_part( ‘menu’, ‘dogs’ ); // Loads the menu-secondary.php template.break;
}
}//else {
//}
?>
- The topic ‘Different menu on each page’ is closed to new replies.