I'm using the following code to set the active state in my menu:
<li class="<?php echo basename($_SERVER['PHP_SELF']) == 'index.php' ? 'active' : '';?>">
<a href="index.php">Home</a></li>
<li class="<?php echo basename($_SERVER['PHP_SELF']) == 'projects.php' ? 'active' : '';?>">
<a href="projects.php">Projects</a></li>
And It works fine for the specific url such as projects.php, but also we had the following "projects" and we want to set the active state in the menu for them:
- project-client-name.php
- project-client-name-2.php
- project-client-name-3.php
Is there any alternative to set the active state to a url who it begins or contains "project" in the url, in this way it works for project-client-name.php and projects.php:
<?php echo basename($_SERVER['PHP_SELF']) == 'project' ? 'active' : '';?>
Thanks in advance.