Reputation: 2176
I've read many answers (many seem to be Wordpress-specific though) but don't understand how to apply them to this situation.
I'm setting an active class on nav items like this:
<li class="<?= ($_SERVER['REQUEST_URI'] == '/about' ? 'active' : ''); ?>">
Is there a way to get php to exclude everything after /about
so the active class gets applied to any child with a parent of /about/
?
Something like this?
'/about/*'
Any pointers in the right direction would be much appreciated.
Upvotes: 0
Views: 101
Reputation: 2877
try this
<li class="<?= (strpos($_SERVER['REQUEST_URI'],'/about') === 0 ? 'active' : ''); ?>">
Upvotes: 1