OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Active Navigation Bar with PHP?

  • Thread starter Thread starter Amine
  • Start date Start date
A

Amine

Guest
I'm trying to make an active navigation bar using PHP where the current page will be highlighted or colored in the navigation bar. The code I used:

Code:
<ul class="topmenu">
  <li <?php if($_GET['page']="home") { ?> class="active" <?php } ?>>
    <a href="home.php"><b>Bienvenue</b></a>
  </li>
  <li <?php if($_GET['page']="livres") { ?> class="active" <?php } ?>>
    <a href="livres.php"><b>Livres</b></a>
  </li>
  <li <?php if($_GET['page']="bibliotheque") { ?> class="active" <?php } ?>>
    <a href="bibliotheque.php"><b>Bibliothèque</b></a>
  </li>
  <li <?php if($_GET['page']="universite") { ?> class="active" <?php } ?>>
    <a href="universite.php"><b>L'université</b></a>
  </li>
  <li <?php if($_GET['page']="contact") { ?> class="active" <?php } ?>>
    <a href=""><b>Contact</b></a>
  </li>
</ul>

The code will put the attribut in the class active if the page is the current page in the navigation bar. However, all the attributs will be given the class active in this case. How do I fix this?

P.S: I am not looking for any JS or jQuery alternatives, I'm trying to make this work with PHP only.
<p>I'm trying to make an active navigation bar using PHP where the current page will be highlighted or colored in the navigation bar. The code I used:</p>

<pre><code><ul class="topmenu">
<li <?php if($_GET['page']="home") { ?> class="active" <?php } ?>>
<a href="home.php"><b>Bienvenue</b></a>
</li>
<li <?php if($_GET['page']="livres") { ?> class="active" <?php } ?>>
<a href="livres.php"><b>Livres</b></a>
</li>
<li <?php if($_GET['page']="bibliotheque") { ?> class="active" <?php } ?>>
<a href="bibliotheque.php"><b>Bibliothèque</b></a>
</li>
<li <?php if($_GET['page']="universite") { ?> class="active" <?php } ?>>
<a href="universite.php"><b>L'université</b></a>
</li>
<li <?php if($_GET['page']="contact") { ?> class="active" <?php } ?>>
<a href=""><b>Contact</b></a>
</li>
</ul>
</code></pre>

<p>The code will put the attribut in the class active if the page is the current page in the navigation bar. However, all the attributs will be given the class active in this case. How do I fix this?</p>

<p><strong>P.S: I am not looking for any JS or jQuery alternatives, I'm trying to make this work with PHP only.</strong></p>
Continue reading...
 

Latest posts

Top