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 Basic PHP Website (2018) Building a Media Library in PHP Adding Active States to the Navigation

hakan Gülay
hakan Gülay
8,489 Points

I am Confused

I Couldn't understand anything about this video! Can anyone explain to me step by step ? Thanks a lot !.

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,682 Points

What's happening is we're adding a class to individual navigation links in our header file so that the page that users are currently viewing is identified and underlined in the navigation.

But we can't just add a static class in the navigation file because as it's a served header file that's imported into the template, the same page would be highlighted no matter what page you're on.

That's why you need a condition statement to check for the current value of the cat variable before then adding the class. This way php will be able to check that the correct class is added to the correct page.

You'll need to set the variable in catalog.php and then reference it in the header.php file.

I hope this helps clear it up. :)