how to add active to a tag and li tag with php

后端 未结 5 1532
情深已故
情深已故 2021-01-24 01:45

Trying to get my PHP navigation bar to work. I am trying to echo the page where the user is on with the attached class of active if the page is current.

Here is my code

5条回答
  •  我在风中等你
    2021-01-24 02:28

    Not tested:

     "Home", 
        "contact.php" => "Contact Us", 
        "services.php" => "services", 
        "employees.php" => "Employees", 
        "dashboard.php" => "Dashboard");
    
    $uri = explode("/", stripslashes($_SERVER['REQUEST_URI']));
    
    foreach ($pages as $url => $label) {
      echo '
  • '.$label.'
  • '; } ?>

    Note: it is a best practice to put your other page files in the root next to yout index.php

提交回复
热议问题