Assign Section and Page IDs


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.