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

lyonel scapino
14,191 PointsShirts 4 Mike Project conditional to underline current page fails
when I type this code in my header.php code page I get a white square around the shirts icon: <li class="shirts<?php if ($section == "shirts") {echo "on"; } ?>"> <a href="shirts.php">Shirts</a></li>
If I remove the php part it gets orange correctly again.
7 Answers

lyonel scapino
14,191 PointsIndeed, inserting the variable does fix the issue, nice debugging!. Thanks.

lyonel scapino
14,191 Pointsthe underlining works in both cases. The problem is that when I put the conditional statement on the shirts line, it creates a white square around the Shirts image. I agree it could be a css problem but I never touched it, only downloaded it from the attached files of the course. Thus I believe the creators of this course would have seen something.

Rodger Hinson
2,183 PointsI think this was missed in the video. I had this problem too and I defined the $section variable in index.php before using it. Like this:
<?php
$pageTitle = "Unique T-shirts designed by a frog";
$section = "";
include('inc/header.php'); ?>
And so forth. Just make sure that it's done BEFORE it loads header.php.

Rodger Hinson
2,183 PointsYep. Just tested it. I commented out php $section = ""
and the white box returned. Apparently you need to declare/initialize the variable before using it.

Ian Hart
4,724 PointsThanks Rodger. I was also getting this problem. Could see by View Page Source it didn't like an undefined variable. Didn't think it was ideal to be adding a variable that is effectively nothing, but hey it works!

Stone Preston
42,016 PointsCan you post the whole conditional you were using. It looks like you may have forgotten to close the php tag like so
?>
But can't be certain without more context

lyonel scapino
14,191 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>

lyonel scapino
14,191 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>

Stone Preston
42,016 Pointsdoes the underlining work with the contact link? your php looks pretty good so it might be an issue with the css styling and not the php.