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
Frank Cameron-Wilson
8,814 Pointsissue with 'adding active states to the navigation'
Hi, I've just finished the 'Creating the Menu & Footer' stage in the 'Build a simple php application' in the last vid 'Adding Active States to the Navigation' says to add this code <?php if ($section == "shirts/contact") { echo "on"; } ?> to the shirt & contact <li class="" >. Adding the code to the contact list item,, no problem,, but adding the same code to the shirts list item gives the shirts button on the index page a white background. I,ve checked the code a hundred times and all i can think is that it's a problem in the style.css?? Please help!!
5 Answers
Frank Cameron-Wilson
8,814 Pointsi've sorted the problem. It turned out that i needed to add a $section = "name"; variable to the index.php file. The video tell you to add this variable to the shirts and contact.php files but not the index.
Boon Kiat Seah
66,664 PointsUnder the index.php, $section variable is empty and it could have caused the problem. I set the variable to "index" and the problem is solved
$pageTitle = "Unique T-shirts designed by a frog";
$section = "index";
Frank Cameron-Wilson
8,814 PointsThat was exactly the problem.. :-)
Graham Davidson
Courses Plus Student 14,966 PointsHI Frank do you have a copy of the code in question so I can take a look.
G
Frank Cameron-Wilson
8,814 PointsThe full list is
<ul class="nav">
<li class="shirts <?php if ($section == "shirts") { echo "on"; } ?>"><a href="shirts.php">Shirts</a></li>
<li class="contact <?php if ($section == "contact") { echo "on"; } ?>"><a href="contact.php">Contact</a></li>
<li class="cart"><a href="#">Shopping Cart</a></li>
</ul>
And in the <li class> tag i've added the conditional statement to it with the $section variable added to the start of the shirts.php and the contact.php.
Frank Cameron-Wilson
8,814 Points<ul class="nav"> <li class="shirts <?php if ($section == "shirts") { echo "on"; } ?>"><a href="shirts.php">Shirts</a></li> <li class="contact <?php if ($section == "contact") { echo "on"; } ?>"><a href="contact.php">Contact</a></li> <li class="cart"><a href="#">Shopping Cart</a></li> </ul>
miguel rodriguez
Courses Plus Student 743 Pointsmiguel rodriguez
Courses Plus Student 743 PointsI tried this and the index.php page does not show an error anymore. But now the active stage on SHIRTS and CONTACT does not work anymore. Any updates on this problem?