Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Sirin Srikier
Sirin Srikier
7,671 Points

Displaying different navigation for different pages on a wordpress site

I am working on a restaurant site where they have 3 different locations. I would like to display different navigation on those different locations by selecting page id and displaying the nav for that site and sub pages. Basically the 3 locations are the microsites. I was thinking of an if statement like this...

<?php if(is_page(1)) //display menu for this page elseif(is_page(2)) //display menu for page 2 else //display selected default menu ?>

I would be selecting it using page ids Any suggestions of where/how to start?

2 Answers

Kevin Korte
Kevin Korte
28,148 Points

That sounds like that would work fine. You can even create the 4 menus in the wordpress dashboard and just call the menu function from the statement that checks which one to show.

Sue Dough
Sue Dough
35,800 Points

Getting it from ID's is usually bad practice. The ID's could easily change in the future. Get the pages by their slugs to make it more bullet proof or their custom templates if applicable.