Skip to content
Advertisement

PHP Page Navigation Optimizing – Setting “active” on nav items

I have my nav.php setup with code like this. This is to determine the page and then set both the navigation header and the item as active.

JavaScript

I then have the following html code.

JavaScript

How can I optimize this as I feel this is horribly done and outdated. I’ve been working on cleaning up all my older code and this is one area I’m not sure about. I know I could technically add the code into the html block itself, but it’s not really any better that way.

I also realize the php code block only partially matches what I posted. I have dozens of links, so to condense the info and present enough, I truncated it down.

I’m also working on revamping my PATH variables to be constants and defined in a single file, its sort of a mess at the moment. 🙂

Advertisement

Answer

Using the approach outlined by @CBroe comment above

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement