Return to Snippet

Revision: 33381
at October 8, 2010 07:46 by villagecreative


Initial Code
// this goes at the top of the document, before the DOCTYPE
<?php $page = basename($_SERVER['SCRIPT_NAME']); ?>


// 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>

Initial URL


Initial Description
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.

Initial Title
Nav with class="active" based on page

Initial Tags
navigation

Initial Language
PHP