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

可以突出显示当前菜单项,但不能将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?

 &lt;?php $ activesidebar [$ currentsidebar] =“id = isactive”;?&gt; \  n 
&lt; div class =“span3”&gt; 
&lt; div class =“well sidebar-nav hidden-phone”&gt; 
&lt; ul class =“nav nav-list”&gt;  
&lt; li class =“nav-header”&lt;?php echo $ activesidebar [1]?&gt;&gt;营销服务&lt; / li&gt; 
&lt; li&gt;&lt; a href =“#”&gt;营销 技术&lt; / a&gt;&lt; / li&gt; 
&lt; li&gt;&lt; a href =“#”&gt;生成更多销售&lt; / a&gt;&lt; / li&gt; 
&lt; li&gt;&lt; a href =“  #“&gt;直接电子邮件营销&lt; / a&gt;&lt; / li&gt; 
 
&lt; li class =”nav-header“&lt;?php echo $ activesidebar [2]?&gt;&gt;广告服务&lt; / li&gt  ; 
&lt; li&gt;&lt; a href =“../ services-advertising-mass-media-network.php”&gt;传统媒体&lt; / a&gt;&lt; / li&gt; 
&lt; li&gt;&lt; a  href =“#”&gt;在线&amp; 社交媒体&lt; / a&gt;&lt; / li&gt; 
&lt; li&gt;&lt; a href =“#”&gt; Media Planing&amp; 购买&lt; / a&gt;&lt; / li&gt; 
 
&lt; li class =“nav-header”&lt;?php echo $ activesidebar [3]?&gt;&gt;技术服务&lt; / li&gt; 
&lt; li&gt;  ;&lt; a href =“#”&gt;托管网站&lt; / a&gt;&lt; / li&gt; 
&lt; li&gt;&lt; a href =“#”&gt;托管网络服务器&lt; / a&gt;&lt; / li&gt;  
&lt; li&gt;&lt; a href =“#”&gt;托管数据库&lt; / a&gt;&lt; / li&gt; 
 
&lt; li class =“nav-header”&lt;?php echo $ activesidebar [4  ]?&gt;&gt;关于我们&lt; / li&gt; 
&lt; li&gt;&lt; a href =“../ aboutus-contactus.php”&gt;联系我们&lt; / a&gt;&lt; / li&gt; 
&lt; /  ul&gt; 
&lt; / div&gt; 
  code>  pre> 
 
 

这会添加到我想要添加的当前页面上。 p>

  &lt;?php $ currentsidebar = 2;  include('module-sidebar-navigation.php');?&gt; 
  code>  pre> 
 
 

我已在每个页面上单独编程此菜单,但要使我的网站动态化我 使用一个文件并使用php includes来加载文件。 我可以在当前页面上突出显示菜单以指定id =“isactive”,如何将id =“notactive”分配给该页面上未激活的其他3个菜单项。 是否有其他或者我必须包含? p> div>

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.