Posted By

relaxasaurus on 12/04/08


Tagged


Versions (?)

Assign Section and Page IDs


 / Published in: PHP
 

Directory = $thisSection. Page file name = $thisPage.

  1. /*
  2. Directory = $thisSection
  3. Page file name = $thisPage
  4. */
  5.  
  6. $parts = Explode('/', $_SERVER["SCRIPT_NAME"]);
  7. $thisSection = $parts[count($parts) - 2];
  8. $thisSection = ($thisSection == "") ? "home" : $thisSection;
  9. $thisPage = end($parts);
  10. $thisPage = str_replace(".php","",$thisPage);
  11.  
  12. // From there you can do things like:
  13.  
  14. function subnav($name,$page) {
  15. global $thisPage;
  16. if($thisPage==$page) {
  17. echo '<li class="active"><a href="'.$page.'.php">'.$name.'</a></li>';
  18. } else {
  19. echo '<li><a href="'.$page.'.php">'.$name.'</a></li>';
  20. }
  21. }
  22.  
  23. if($thisSection=="about") {
  24. subnav("About Us", "about");
  25. subnav("History", "history");
  26. subnav("Contact Us", "contact");
  27. }

Report this snippet  

You need to login to post a comment.