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

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

    Do like this :

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

提交回复
热议问题