PHP Build a Basic PHP Website Building a Media Library in PHP Adding Active States to the Navigation

Anthony Fowler
Anthony Fowler
6,749 Points

My Code works as shown but I am wondering how or why echo " on" has this effect.

It seems to be that the underlining of the nav element is possibly done through CSS and This echo "on" is possibly creating a class? I don't quite understand what is happening here. Any help would be much appreciated!

1 Answer

Dave Faliskie
Dave Faliskie
17,768 Points

The purpose for using the echo " on" is to add the class .on (which just underlines the text) to the nav link if it meets the condition set.

So what that php code is doing is comparing the $section variable, set on each page, to the name of the link. Ex. the $section = 'book' means your on the book page so echo " on". Or in other words if they are the same add the class "on"