/ Published in: PHP

This is a way to have a navigation menu with active classes which are set according to what page is loaded. This only works on .php pages.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// this goes at the top of the document, before the DOCTYPE // This goes in the page, either hard-coded, or by an include <ul id="nav"> <li <?php if ($page == 'index.php') { ?>class="active"<?php } ?>><a href="index.php" title="Welcome page">Home</a></li> <li <?php if ($page == 'about.php') { ?>class="active"<?php } ?>><a href="about.php" title="About us page">About</a></li> <li <?php if ($page == 'services.php') { ?>class="active"<?php } ?>><a href="services.php" title="Services page">Services</a></li> <li <?php if ($page == 'news.php') { ?>class="active"<?php } ?>><a href="news.php" title="News page">News</a></li> <li <?php if ($page == 'testimonials.php') { ?>class="active"<?php } ?>><a href="testimonials.php" title="Testimonials page">Testimonials</a></li> <li <?php if ($page == 'contact_us.php') { ?>class="active"<?php } ?>><a href="contact_us.php" title="Contact us page">Contact us</a></li> </ul>
Comments
