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

Henry Lin
Henry Lin
11,636 Points

I am confused by the class on Help Please!

Hi guys, I am currently working on the video "Adding Active States to the Navigation" for PHP. I am not sure how this piece of code affects the website. <li class="books<?php if ($section=="books") {echo " on"; } ?>"> I assume that this code does the following things: li class = books => assign the list value a class named books the php code segment says, hey check if $section variable has a value and if the value is "books". if it is books then set the class = "on" So when we load this page, the browser would apply proper css code to this list item. Am i right ??

2 Answers

Henry Lin
Henry Lin
11,636 Points

Just for those who have same question as I did. A html tag(element) could have several class.. that's why we need a php conditional function to control the "on" string ..

I just forgot about the html tag things...

Oliver Burge
Oliver Burge
1,157 Points

Simply put it is adding the "on" class depending on which section you are currently visiting. If you go into the css file and do a search you will find this : .header .nav li.on a {text-decoration:underline;} which just adds an underline for the "on" class.