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

nav-sprite.png for shirt appears with white background

I've completed the Creating the Headers and Footers section. I embedded the code to underline the Shirts and Contact. The image for Shirts now displays as a white box when you navigate to the home page (index.php). How do I fix this?

2 Answers

Hi Joseph,

You might notice the "shirts" and "contact" link are underlined too.

The reason this is happening on the homepage is because the $section variable is undefined on that page because we didn't need to use it. However, the scripts in the navigation are still running and we're checking if an undefined variable is equal to something. This is causing a php error.

To avoid this we can use the php isset() function to make sure that the variable is set first, before we try to see if it is equal to something.

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

If you would like more details about this, like why the background was white or why the links were underlined then I wrote more about this in another post here: https://teamtreehouse.com/forum/creating-the-menu-and-footer-render-error

That worked! Thank you for your help, Jason.