Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.


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