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

PHP

issue 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

i'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.

I 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?

Under 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";

That was exactly the problem.. :-)

HI Frank do you have a copy of the code in question so I can take a look.

G

The 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.

<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>