可以突出显示当前菜单项,但不能将class =添加到样式未加标签的菜单项中

<?php $activesidebar[$currentsidebar]="id=isactive";?>

<div class="span3">
<div class="well sidebar-nav hidden-phone">
<ul class="nav nav-list">                   
    <li class="nav-header" <?php echo $activesidebar[1] ?>>Marketing Services</li>
    <li><a href="#">Marketing Technology</a></li>
    <li><a href="#">Generate More Sales</a></li>
    <li><a href="#">Direct Email Marketing</a></li>

    <li class="nav-header" <?php echo $activesidebar[2] ?>>Advertising Services</li>
    <li><a href="../services-advertising-mass-media-network.php">Traditional Medias</a></li>
    <li><a href="#">Online & Social Medias</a></li>
    <li><a href="#">Media Planing & Purchasing</a></li>

    <li class="nav-header" <?php echo $activesidebar[3] ?>>Technology Services</li>
    <li><a href="#">Managed Websites</a></li>
    <li><a href="#">Managed Web Servers</a></li>
    <li><a href="#">Managed Databases</a></li>

    <li class="nav-header" <?php echo $activesidebar[4] ?>>About Us</li>
    <li><a href="../aboutus-contactus.php">Contact Us</a></li>
</ul>
</div>

This is added to the current page I want to add this on.

<?php $currentsidebar =2; include('module-sidebar-navigation.php');?>

I had programmed this menu individually on each page, but to make my website dynamic I used one file and use php includes to load the file. I can get the menu to highlight on the current page assigning an id="isactive", how can I assign id="notactive" to the other 3 menu items that are not active on that page. Is there an else or elseif I have to include?

Reset the array before setting your preferred index.

for ($i = 0; $i < 4; $i++) {
     $activesidebar[$i] = "class=\"noactive\"";
}

Notes:

  • PHP array indices start from 0, not 1.
  • ID's are meant to be unique (ie, there cannot be 2 of the same ID). Use a classname instade.