Warning - I'm a front end designer; Please pardon my fumbling of the PHP concepts here
So I've got a PHP statement that basically outputs a class in my markup when the URL of the page matches the statement. Here it is:
<?php if (strpos($_SERVER["REQUEST_URI"],"/technology") === false) {} else { echo "current"; } ?>
As is, I'm using the statement inside a class attribute on an <a>
tag inside of a <nav>
element to add a class of "current" so that I can style that nav
element differently for the page your currently on. As is, it works fine for the site main navigation, because it returns as true even for pages deeper than just /technology
, such as /technology/security
which is what I want for the sitewide nav.
The problem is I'd like to use a similar but modified version of this code on subsection navigations that will only appear on the main subpage categories.
So in those cases, I only want the result to be true when the exact URL is matched. More specifically, I want to exclude the parent (ie. /technology
) even when I'm on /technology/security
.
So how can I modify the statement to evaluate that way?