Posted By

neilp123 on 11/03/10


Tagged


Versions (?)

Use php to highlight the current page


 / Published in: PHP
 

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.

  1. <?php $currentPage = basename($_SERVER['SCRIPT_NAME']); ?>
  2. <div id="nav">
  3.  
  4. <ul>
  5. <li><a href="index.php"<?php if($currentPage == 'index.php') { echo 'id="current"'; } ?>>home</a></li>
  6.  
  7. <li><a href="about.php" <?php if($currentPage == 'about.php') { echo 'id="current"' ;} ?>>About us</a></li>
  8.  
  9. <li><a href="portfolio.php" <?php if($currentPage == 'portfolio.php') { echo 'id="current"'; } ?>>Portfolio</a></li>
  10.  
  11. <li><a href="contact.php" <?php if($currentPage == 'contact.php') { echo 'id="current"'; } ?>>contact</a></li>
  12. </ul>
  13.  
  14. </div><!-- END nav -->

Report this snippet  

You need to login to post a comment.