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

后端 未结 5 1411
情深已故
情深已故 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:22

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

    This should work for you. Because, you were trying to access the url address using GET-METHOD. Here, I have fetched your url by doing $cururl = $_SERVER['PHP_SELF']; and checked for the active menu item as if (strpos($cururl,$url)!==false)

提交回复
热议问题