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 Build a Simple PHP Application Creating the Menu and Footer Adding Active States to the Navigation

I seemed to have done everything right, but the shirts navbar link still does not have an underline?

So this is my code, which is supposed to underline the word Shirts in the navbar. It's still not working though. Contact page seems to be working fine.

The corresponding page has the right code in them I think.

<?php

$section = "shirts";

For some reason, the shirts code is not displaying here, only the contact page code.

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

2 Answers

If you right click and inspect the link that should be selected (underlined), has it got the correct class?

I found out that my code was correct. I made a new post about this on the forum. The code executed correctly only after I copied and pasted the exact same code below and refreshed. Then there were two "Shirt" Navbar links, both underlined.

I then deleted the new code and left it as it was originally (when it was not working the first time) and refreshed. This time, it worked. Basically, it simply did not execute the first time even though everything was correct.

Right now, in my question above, I can see that my code for the "Shirts" section is there. When I posted it earlier, it wasn't.

This is not the first time my code has not executed even though there was nothing wrong with it. I'm not sure why this is happening.

Unless you examined the output on the page, you'll never know if it was your code ;)

If your code outputted the correct class onto the list element, and your code was perfect, it sounds like a cache issue in your browser. You can avoid this by doing a hard refresh (mac: cmd + shift + r) or opening a secret / private / incognito browsing window - i.e. a window that won't use previously cached styles and will only cache assets for the browsing session.

I did examine the output. That's how I knew it wasn't working. But that's a great idea! I will always use a hard refresh from now on to make sure what I am seeing is correct. Thank you so much for taking the time to help me with this :D

Frank van Oudhuizen
Frank van Oudhuizen
2,672 Points

I was having the same issue. Turned out I forgot to save the "shirts" file...

doh!