Find targeted #id from parent includer with php

49 views Asked by At

I have this code that I include with a require_once(). I'm looking to set the link's class to "Active" if the user is on it's page. I've managed to do so if the link is intended for a file but I have no clue on how to proceed for the url ./index.php#About as this code will also match ./index.php. Also, I'd rather not use variables on each page and check them afterwards like explained in this post.

<a href="./" id="Nav-Title"></a>
<a href="./account.php" <?php if(basename(get_included_files()[0], '.php') == "account") echo 'class="Active"';?>>Mon Compte<span>2</span></a>
<a href="./login.php" <?php if(basename(get_included_files()[0], '.php') == "login") echo 'class="Active"';?>>Se Connecter</a>
<a href="./#About">À Propos</a>
<a href="./discover.php" <?php if(basename(get_included_files()[0], '.php') == "discover") echo 'class="Active"';?>>Découvrir</a>
<a href="./search.php" <?php if(basename(get_included_files()[0], '.php') == "search") echo 'class="Active"';?>>Trouver</a>

Thanks for your help!

0

There are 0 answers