Return to Snippet

Revision: 35120
at November 3, 2010 00:52 by neilp123


Updated Code
<?php $currentPage = basename($_SERVER['SCRIPT_NAME']); ?>
<div id="nav">
  
  <ul>
   <li><a href="index.php"<?php if($currentPage == 'index.php') { echo 'id="current"'; } ?>>home</a></li> 

   <li><a href="about.php" <?php if($currentPage == 'about.php') { echo 'id="current"' ;} ?>>About us</a></li>

   <li><a href="portfolio.php" <?php if($currentPage == 'portfolio.php') { echo 'id="current"'; } ?>>Portfolio</a></li>
    
   <li><a href="contact.php" <?php if($currentPage == 'contact.php') { echo 'id="current"'; } ?>>contact</a></li> 
    </ul>
    
  </div><!-- END nav -->

Revision: 35119
at November 3, 2010 00:50 by neilp123


Initial Code
<?php $currentPage = basename($_SERVER['SCRIPT_NAME']); ?>
<div id="nav">
  
  <ul>
   <li><a href="index.php"<?php if($currentPage == 'index.php') { echo 'id="current"'; } ?>>home</a></li> 

   <li><a href="about.php" <?php if($currentPage == '#') { echo 'id="current"' ;} ?>>About us</a></li>

   <li><a href="portfolio.php" <?php if($currentPage == '#') { echo 'id="current"'; } ?>>Portfolio</a></li>
    
   <li><a href="contact.php" <?php if($currentPage == 'contact.php') { echo 'id="current"'; } ?>>contact</a></li> 
    </ul>
    
  </div><!-- END nav -->

Initial URL


Initial Description
What this does is takes the name of your document using the basename function. And then you echo out the current id (id="current") if this page is present. Then using CSS we can give the current id an active color.

Initial Title
Use php to highlight the current page

Initial Tags


Initial Language
PHP