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

Avery Freeman-wheaton
Avery Freeman-wheaton
2,273 Points

Problem with Randy Hoyt "Adding Active States" video -- underline persists, also white space around navigation icon

Having trouble with $section variable in PHP, sets underline to 'on' in navigation bar, but the underline persists when changing pages. Also, in the 'shirts' page alone, there is a white border behind the 'shirts' icon and the underline persists in 'contact'. However, in 'contact', it appears to work OK (white border and underline do NOT persists in 'shirts').

Here's the error that occurs on the 'shirts' page:

active_states_navbar_error

See how "contact" is still underlined and "shirts" has a white block around it?

But here's what it looks like on the 'contact' page (looks as if behaving normally):

active_states_navbar_contact

Here's my header.php file relevant to this code:

<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 <?php if ($section == "cart") {echo "on"; } ?>"><a href="cart.php">Shopping Cart</a></li>
</ul>

And here's the assignment of the variables in shirts.php and contact.php, respectively:

<?php 
//init page title before referencing in 'header.php'
$page_title = "These are shirts";
$section = "shirts";

include ('includes/header.php');
?>
<?php 
//init page title before referencing in 'header.php'
$page_title = "Contact Mike";
$section = "contact";

include ('includes/header.php');
?>

Really not sure what I did wrong!!

I'm getting a lot out of this lesson and I'd really like to implement this functionality in my own website, so if I could have some help I'd really appreciate it!

Thanks, Avery

Lukas Smith
Lukas Smith
4,026 Points

can U show us how looks class "shirts" in css ?

1 Answer

Avery Freeman-wheaton
Avery Freeman-wheaton
2,273 Points

Hi ---

I managed to fix this problem,

Deleted "index.html" added $session = "index";

reloaded and it went away... Yay!