Different Navigation Menus For Different Pages


Author Message
teewil

Posted: 11/14/2011
Quote message 

Hello. Hoping someone out there can help me with this. I've been trying to come up with the solution on my own for days, including working with plugins, but have not found a fix.

Here's the problem:

In the default, each page / post in Wordpress has the same navigational menu (the horizontal menu typically just below the header image). I want to apply a different navigational menu to certain pages.

Within Wordpress one can create various navigational menus. Let's call them navigational menu 1, 2, 3, 4. I would like to use navigational menu 1 for page B, navigational menu 2 for page C, navigational menu 3 for page D, and navigational menu 4 for all the rest of my pages / posts.

I know that this can be done with various themes by altering some code in the header.php file. In fact here's a url that explains how to do this - http://wordpress.org/support/topic/custom-menus-on-different-pages . But the code in the header.php file produced by Artisteer does not match the code in the help url above.

I'm guessing there is a way to do this with Artisteer generated Wordpress themes, but I can't figure it out. Anyone have an idea?
 
Abland

Posted: 11/15/2011
Quote message 

Hi, teewil,

For an Artisteer 3.0 theme, in your theme's "functions.php find approximately line 44:
if (function_exists('register_nav_menus')) {

register_nav_menus(array('primary-menu' => __( 'Primary Navigation', THEME_NS)));
}

Add three more menus:
if (function_exists('register_nav_menus')) {

register_nav_menus(array('primary-menu' => __( 'Primary Navigation', THEME_NS)));
register_nav_menus(array('secondary-menu' => __( 'Secondary Navigation', THEME_NS)));
register_nav_menus(array('tertiary-menu' => __( 'Tertiary Navigation', THEME_NS)));
register_nav_menus(array('quaternary-menu' => __( 'Quaternary Navigation', THEME_NS)));
}

Now, in wp admin > Appearance > Menus you'll see you have four menus under "Theme Locations". Assign a custom menu to each of the four.

For demo purposes we want the following menus for the following page id's:
Primary: all remaining pages
Secondary: page id's 1, 2
Tertiary: page id's 3, 4
Quaternary: page id 5

In your theme create a "templates folder" and inside create a file, swap-menu.php: (using the menu code from header.php)
<?php 

if (is_page(array(1,2))) {
echo theme_get_menu(array(
'source' => theme_get_option('theme_menu_source'),
'depth' => theme_get_option('theme_menu_depth'),
'menu' => 'secondary-menu','class' => 'art-hmenu'
)
);
} else if (is_page(array(3,4))) {
echo theme_get_menu(array(
'source' => theme_get_option('theme_menu_source'),
'depth' => theme_get_option('theme_menu_depth'),
'menu' => 'tertiary-menu','class' => 'art-hmenu'
)
);
} else if (is_page(5)) {
echo theme_get_menu(array(
'source' => theme_get_option('theme_menu_source'),
'depth' => theme_get_option('theme_menu_depth'),
'menu' => 'quaternary-menu','class' => 'art-hmenu'
)
);
} else {
echo theme_get_menu(array(
'source' => theme_get_option('theme_menu_source'),
'depth' => theme_get_option('theme_menu_depth'),
'menu' => 'primary-menu','class' => 'art-hmenu'
)
);
}
?>

Now in "header.php" replace the menu code:
<?php

echo theme_get_menu(array(
'source' => theme_get_option('theme_menu_source'),
'depth' => theme_get_option('theme_menu_depth'),
'menu' => 'primary-menu','class' => 'art-hmenu'
)
);
?>

With a call to the new file:
<?php

get_template_part('templates/swap','menu');
?>

 
teewil

Posted: 11/15/2011
Quote message 

Hello Abland! Thank you for your assistance. I followed your directions, correctly I believe, and the end result was the navigation menu disappearing entirely. No menu on any pages. Any ideas? Thanks.
 
Abland

Posted: 11/15/2011
Quote message 

Hi, teewil,

First, your new file is in your theme: "templates/swap-menu.php"?

Second, did you change the page id's in the above code for your own site's page id's?
 
teewil

Posted: 11/15/2011
Quote message 

Hi Abland. Thanks for the fast response. Very much appreciated. I did place the swap menu file into my template files and I did place the proper pages into the file. According to the swap menu file, pages that are not specified for a particular menu should show the primary menu, correct? Problem is non-specified pages are showing no menu at all. None of the pages are showing a menu, as I mentioned. Thanks for any help you can provide in clearing this up.
 
Abland

Posted: 11/15/2011
Quote message 

Hi, teewil,

You already had a "templates" folder? Which version is your Artisteer? My instructs were for version 3.0.
 
teewil

Posted: 11/15/2011
Quote message 

I'm using version 3.0. Now when you say templates, I'm assuming you mean the templates that are assembled under Appearance > Editor in Wordpress. Am I mistaken in that? Should I be placing the swap file elsewhere? I uploaded the file into my theme's folder and it now appears under Templates on the Edit Themes page (Appearance > Editor). I'm thinking the placement of the file may be the problem.
 
Abland

Posted: 11/15/2011
Quote message 

Hi, teewil,

In wp-admin > Appearance > Menus are the four menu places available under Theme Locations?

If yes, when you selected a menu for each did you save with the button in the Theme Locations area?
 
Abland

Posted: 11/15/2011
Quote message 

Hi, teewil,

Sorry, I meant create a new folder called templates, however in your header.php change:
<?php 

get_template_part('templates/swap','menu');
?>

to
<?php 

get_template_part('swap','menu');
?>

That will call the file from the theme root where you have it.
 
teewil

Posted: 11/15/2011
Quote message 

Shazam! Changed the header code per your instructions and now working. Exactly what I was looking for. You're a genius Abland. Thank you so much for your help.
 
Britt

Posted: 11/21/2011
Quote message 

Hey Abland!

I love how it works one of the primary pages, but doesn't work in the sub pages.

This is how my multiple pages coding looks:

if (is_page(array(802,88,108,157,289,292,77))) {


Really cool to see how it works on the primary pages.
 
Britt

Posted: 11/21/2011
Quote message 

Rock On!!! All the 7 Shopping Cart Items are all working perfectly!

No Just trying to get the other custom menus working in the shopping cart and checkout and the members area.
 
Britt

Posted: 11/21/2011
Quote message 

Quote Abland:


In the custom menu, all the primary and sub-links are showing as text links only. The buttons have disappeared.

Any ideas?




 
Britt

Posted: 11/21/2011
Quote message 

I don't know how I did this, but I got the buttons to work one way perfectly on the secondary custom menu with 7 page id's, but the 3rd was broken on one of the 2 page id's, and the 4th custom menu is broken on 7 out of 8 page id's.

Another way I got this working but the buttons disappear while showing all the text links as one for the primary and secondary.

The only difference I can see is the extra ) symbol when calling for the second custom menu called checkout.

In the 1st scenario my code looks like:

<?php

if (is_page(array(802,88,108,157,289,292,77))) {

echo theme_get_menu(array(

'source' => theme_get_option('theme_menu_source'),

'depth' => theme_get_option('theme_menu_depth'),

'menu' => 'shopping-menu','class' => 'cpn_hmenu'
) );


} else if (is_page(78,79,82)) {

echo theme_get_menu(array(

'source' => theme_get_option('theme_menu_source'),

'depth' => theme_get_option('theme_menu_depth'),

'menu' => 'checkout-menu','class' => 'cpn_hmenu'
) );


} else if (is_page(387,375,446,365,850,499,709,884)) {

echo theme_get_menu(array(

'source' => theme_get_option('theme_menu_source'),

'depth' => theme_get_option('theme_menu_depth'),

'menu' => 'members-menu','class' => 'cpn_hmenu'

) );


} else {

echo theme_get_menu(array(

'source' => theme_get_option('theme_menu_source'),

'depth' => theme_get_option('theme_menu_depth'),

'menu' => 'primary-menu','class' => 'cpn_hmenu'

) ); } ?>





The 2nd where only the text links appear:




<?php

if (is_page(array(802,88,108,157,289,292,77))) {

echo theme_get_menu(array(

'source' => theme_get_option('theme_menu_source'),

'depth' => theme_get_option('theme_menu_depth'),

'menu' => 'shopping-menu','class' => 'cpn-hmenu'

)

);

} else if (is_page(array(78,79,82))) {

echo theme_get_menu(array(

'source' => theme_get_option('theme_menu_source'),

'depth' => theme_get_option('theme_menu_depth'),

'menu' => 'checkout-menu','class' => 'cpn-hmenu'

)

);

} else if (is_page(387,375,446,365,850,499,709,884)) {

echo theme_get_menu(array(

'source' => theme_get_option('theme_menu_source'),

'depth' => theme_get_option('theme_menu_depth'),

'menu' => 'members-menu','class' => 'cpn-hmenu'

)

);

} else {

echo theme_get_menu(array(

'source' => theme_get_option('theme_menu_source'),

'depth' => theme_get_option('theme_menu_depth'),

'menu' => 'primary-menu','class' => 'cpn-hmenu'

)

);

}

?>


Uuuggghhh, i feel like im so close after dayz of trying to make something work...
 
Britt

Posted: 11/21/2011
Quote message 

Quote Abland:


May I give you an admin's account in the WP?



 
Britt

Posted: 11/21/2011
Quote message 

Sorry for all the postings, but it seems to be working as I had to change the code to:

cpn_hmenu
 
Abland

Posted: 11/21/2011
Quote message 

Hi, Britt,

The best part of a coding project is looking back on it :-D. Glad it's working - I often need to remind myself to check the prefix. Good catch.
 
Britt

Posted: 11/21/2011
Quote message 

Quote Abland:

Thank you so much Abland!!! :-P

WOW!

This is Amazing how this is working perfectly w/ 3 custom menus and18 page id's

Hope people notice how you have to add the array if your using multiple page id's and take it out if your using just one.

Are you able to do the same thing for categories/sub cats too?

Your the best Abland



 
Darren

Posted: 11/23/2011
Quote message 

How would this be modified to change the custom side bar menus to be different on different pages?
 
Britt

Posted: 11/25/2011
Quote message 

Quote Darren :

How would this be modified to change the custom side bar menus to be different on different pages?


I use a plugin called Dynamic Widgets found @ WP:
http://wordpress.org/extend/plugins/dynamic-widgets/

 
Britt

Posted: 11/25/2011
Quote message 

Quote Abland:

Hey Abland!

I was wondering how to do this in postings and categories/sub-cats.

I'm guessing in either one, in the swap menu php file, just change the is_page to is_post and for categories to is_category?

Thanks again Abland



 
DivaVocals

Posted: 11/26/2011
Quote message 

This was very helpful.. thanks... :-)
 
Darren

Posted: 11/28/2011
Quote message 

I looked the dynamic-widgets plugin and I see it lets me select what widgets a page displays, but al looking for a way to display a different vertical menu on each page, any ideas

Quote Britt:

Quote Darren :

How would this be modified to change the custom side bar menus to be different on different pages?


I use a plugin called Dynamic Widgets found @ WP:
http://wordpress.org/extend/plugins/dynamic-widgets/



 
Pegaan

Posted: 3/22/2012
Quote message 

Quote Abland:

Hi, teewil,

For an Artisteer 3.0 theme, in your theme's "functions.php find approximately line 44:
if (function_exists('register_nav_menus')) {

register_nav_menus(array('primary-menu' => __( 'Primary Navigation', THEME_NS)));
}

Add three more menus:
if (function_exists('register_nav_menus')) {

register_nav_menus(array('primary-menu' => __( 'Primary Navigation', THEME_NS)));
register_nav_menus(array('secondary-menu' => __( 'Secondary Navigation', THEME_NS)));
register_nav_menus(array('tertiary-menu' => __( 'Tertiary Navigation', THEME_NS)));
register_nav_menus(array('quaternary-menu' => __( 'Quaternary Navigation', THEME_NS)));
}


etc etc.. I did this, everything works great, BUT i have english menu and german menu, now i only have german menu. the english one has totally disappeared. any sugestions? please, please. i am about 2 hours from finishing the job and now stuck with a german menu.
 
John

Posted: 12/18/2012
Quote message 

How would we do this in Artisteer 4?

thanks
 
Gerard

Posted: 6/7/2014
Quote message 

Help i need a way to set up my menu bar so it is different on every pg.
 
neverone

Posted: 6/7/2014
Quote message 

hopefully it's not too late, but, i've had exactly the same problem and found a workaround solution for it.

here's what i did:

i installed this plugin first:
https://wordpress.org/plugins/menu-items-visibility-control/
this allows to to add conditions for each menu item in a shape of a tag code. this way you can include/exclude a certain menu element from a certain page.

then i made one menu with all links and elements that i would use in my site, and by adding conditional codes i managed to exclude certain menu elements when certain page loads.

granted, i have only two pages, and only 12 menu items, but it can be done. you can also use it to exclude/include items based on the device (pc or mobile). works flawlessly, and tested on chrome, firefox and IE

its currently active on my page: http://n1-design.com.hr by clicking on ENG or HRV, you are directed to a different page, that actually have THE SAME menu, just with different items excluded.
 
Penelope

Posted: 6/30/2018
Quote message 

Quote neverone:

hopefully it's not too late, but, i've had exactly the same problem and found a workaround solution for it.
here's what i did:
i installed this plugin first:
https://wordpress.org/plugins/menu-items-visibility-control/
this allows to to add conditions for each menu item in a shape of a tag code. this way you can include/exclude a certain menu element from a certain page.


Thanks neverone it didnt work for me but you put me on the right track.

I have a website with pages in 2 languages English and French and I needed to swap the menu at the top for each language.
I searched for hours to try to find a way of doing such a simple thing until I came across this thread.
I am using Artisteer 4 and this is the solution that worked for me. I am publishing it here to help others with the same problem.

I used a plugin "Category Tag Pages" to assign categories to each page. I chose "en" for the english and "fr" for the french pages.
I followed ABlans advice to add a secondary menu in my theme (see his first post above)

I installed a plugin called "conditional menus"
In "appearance-menus" on the dashboard, I created 2 menus one in english (primary menu)
and one in french (secondary menu)

In the "manage locations tab" you can set the menus to show or not to show.
The plug-in allows you to use the category tag to show or hide the menu using conditions
It took me a while to configure it to work correctly but it works!

The settings I used are as follows:

Primary Navigation menu-en
menu-en condition cat=en
menu-fr condition cat=fr
Disable Menu condition cat=fr

Secondary Navigation menu-fr
menu-fr condition cat=fr
menu-en condition cat=en
Disable Menu condition cat=en
Hope this helps

 
Foler

Posted: 8/3/2018
Quote message 

Thanks! I was looking for suc info for me too. I have got some Best News Portal WordPress Themes from https://www.templatemonster.com/category/news-portal-wordpress-themes/ and now I need to make a website. I think this thread will help me with it
 
Walter Marshall

Posted: 10/8/2018
Quote message 

Hello guys and girls, I am done redesigning my website - http://under-the-open-sky.com. Can you please review my website. How can I improve the appearance of the it? Thanks!