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 trialByron Anderson
7,009 Pointsheader appearance all screwy after applying conditionals! (why??)
my index page now shows a big white block over/around the SHIRTS page link: after applying conditional codes to show the underline indicating the nav link is of the current page, this effect appeared. In the video, he doesn't navigate to the index page (just SHIRTS and CONTACT, showing the code worked), so I wasn't able to determine if he had this same issue, or not. Please & Thank You!
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Byron,
This happens because the $section variable is undefined on the home page. It was never set to a value because it wasn't needed. php outputs a notice error which causes the problems you see on the page.
One solution is to set the section variable to something on the index page. $section = home;
for example, but you have to remember to always do this for every page whether the variable is needed on that page or not.
The solution I went with is to check first if the $section variable is set before trying to use it.
<li class="shirts<?php if ( isset($section) && $section == "shirts") { echo " on"; } ?>"><a href="shirts.php">Shirts</a></li>
<li class="contact<?php if ( isset($section) && $section == "contact") { echo " on"; } ?>"><a href="contact.php">Contact</a></li>
Byron Anderson
7,009 PointsByron Anderson
7,009 Pointsthat worked!
I'm sorry it took me this long to respond, funny thing was that when I published this set of work to my server/site, the issue I had with that white block around the SHIRTS link in the banner of my root index page was gone.
I don't understand how, or why it was only appearing as a problem on my localhost address, but alas...
anyway, you were right. There needed to be a $section variable set to the value "home" under the $pageTitle variable on the index.php file in the root directory to the site.
excellence! Thank You.