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
Jonathan Grieve
Treehouse Moderator 89,590 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. :)