简体   繁体   English

使用PHP和Twitter Bootstrap的动态下拉菜单

[英]Dynamic dropdown menu using php with twitter bootstrap

Thank you for reading... I have a 2 layer of navigation. 谢谢您的阅读...我有2层导航。 which sort the content by good, bad and comment count. 按好,坏和评论数对内容进行排序。 if user clicks on good it will bring another nav which is sort the content by time. 如果用户点击商品,它将带来另一个导航,该导航按时间对内容进行排序。 such as today, last one week, last one month. 例如今天,过去一个星期,过去一个月。

I can add class='active' using $_SERVER['PHP_SELF'] but twitter bootsrap dropdown menu does not have simple class='active' it is complicated. 我可以使用$_SERVER['PHP_SELF']添加class='active'但是twitter bootsrap下拉菜单没有简单的class='active'这很复杂。 I am not able to come up with a solution. 我无法提出解决方案。 should I use for? 我应该用吗? foreach? foreach? I don't know. 我不知道。 please see the html command in the code. 请参阅代码中的html命令。 this is my code. 这是我的代码。

<ul class="nav nav-tabs">
        <li <?php if (basename($_SERVER['PHP_SELF']) == '/?Top'): ?> class="active"<?php endif; ?>><a href="/?Top">Top Content</a></li> 
        <li <?php if (basename($_SERVER['PHP_SELF']) == '/?Bad'): ?> class="active"<?php endif; ?>><a href="/?Bad">Bad Content</a></li>
        <li <?php if (basename($_SERVER['PHP_SELF']) == '/?Comments'): ?> class="active"<?php endif; ?>><a href="/?Comments">Most Commented</a></li>
<!-- It's confusing me when It comes here... because as you see active option is not li tag. it's bunch of html code and also any url bellow can ben any of those up -->
          <li class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-time"></i> Today <b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="URL=week" />Last 1 Week</a></li>
              <li><a href="URL=month" />Last 1 Month </a></li>
              <li><a href="URL=all" />All</a></li>
            </ul>
          </li>
    </ul>

html commend: It's confusing me when It comes here... because as you see active li is not li it's bunch of html code and also also any url below can be any of those up html推荐:当它来到这里时,这让我感到困惑...因为您看到活动的li不是li,所以它是一堆html代码,而且下面的任何url都可以是其中的任何一个

You can use the "active" class for the outter li (the one has class "dropdown" ) and another "active" class in your child dropdown. 您可以对外部li使用"active"类(一个类具有"dropdown"类),而在您的孩子下拉列表中使用另一个"active"类。

This is an example 这是一个例子

<ul class="nav nav-tabs">
    <li class=""><a href="#">Home</a></li>
    <li><a href="#">Help</a></li>
    <li class="dropdown active">
      <a href="#" data-toggle="dropdown" class="dropdown-toggle">Dropdown <b class="caret"></b></a>
      <ul class="dropdown-menu">
        <li><a href="#">Action</a></li>
        <li class="active"><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a href="#">Separated link</a></li>
      </ul>
    </li>
  </ul>

A live demo in JSBin JSBin的现场演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM