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 trialDiego Villaseñor
12,615 PointsInclude submenu via If conditional
Hello everyone,
I have a site in which a submenu should appear only on certain pages. In mi header.php file I have used the following conditional
<?php if ($section=="PLMDLC" OR "EPEA" OR "21N" OR "RR"){include("inc/nav2.php");}?>
Right now, the submenu appears on all pages, independently of the $section name.
What would you recommend doing?
Thanks
2 Answers
Robert Komaromi
11,927 PointsYou don't have your conditional set up correctly. It should be:
<?php if ($section=="PLMDLC" OR $section=="EPEA" OR $section=="21N" OR $section=="RR"){include("inc/nav2.php");}?>
Everything between the or
keyword is evaluated as a separate statement. Because a string like "EPEA" is evaluated as true, your original statement will always return true.
Diego Villaseñor
12,615 PointsOh, thanks Robert!