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 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 91,252 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. :)