我在试图理解一些 php 代码时遇到了一些麻烦。解释:
我有一个由引导程序制成的导航栏。我希望这个导航栏根据页面更改它的活动类。我在导航栏中有一个带有 li 类“下拉菜单”的子导航。当此页面处于活动状态时,此 li 类想要更改为“下拉活动”当其他页面处于活动状态时,他们只想要一个简单的“活动”类。
我的代码如下: PHP:
$pageLoc = 'where';
$nav_items = array('index'=>'Home', 'where'=>'Where?', 'appeals'=>'Current Appeals', 'news'=>'Latest News', 'events'=>'Events', 'dontate'=>'Dontate', );
$nav_sub = array('africa'=>'Africa', 'bangladesh'=>'Bangladesh', 'gaza'=>'Palestine/Gaza', 'kashmir'=>'Kashmir', 'pakistan'=>'Pakistan', 'uk'=>'United Kingdom' );
foreach ($nav_items as $nav_href=>$nav_title) {
if ($pageLoc == $nav_href) && ($pageLoc == 'where') {
echo '<li class="dropdown active">' . $nav_title . '</li>';
}
elseif ($pageHref == $nav_href) && ($pageLoc == 'no') {
echo '<li class="dropdown">' . $nav_title . '</li>';
}
elseif ($pageHref == $nav_href) {
echo '<li class="active">' . $nav_title . '</li>';
}
else {
echo '<li>' . $nav_title . '</li>';
}
}
导航栏:
<ul class="nav pull-right">
<li class="pull-right">
<a class="btn-danger" href="donate"><i class="icon-medkit"> DONATE!</i></a>
</li>
</ul>
<ul class="nav pull-right">
<li class="">
<a href="../">Home</a>
</li>
<li class="dropdown">
<a href="../where/" class="dropdown-toggle disabled" data-toggle="dropdown">
Where?
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li class="nav-header">Where we operate</li>
<li class="divider"></li>
<li><a href="../where/africa">Africa</a></li>
<li><a href="../where/bangladesh">Bangladesh</a></li>
<li><a href="../where/palestine-gaza">Palestine/Gaza</a></li>
<li><a href="../where/kashmir">Kashmir</a></li>
<li><a href="../where/pakistan">Pakistan</a></li>
</ul>
</li>
<li class="">
<a href="../appeals">Current Appeals</a>
</li>
<li class="">
<a href="../news">Latest News</a>
</li>
<li class="">
<a href="../events">Events</a>
</li>
</ul>
我知道这个 php 正在生成语法错误。不幸的是,我不是专业人士!:( 这是
what I originally had:
foreach ($nav_items as $nav_href=>$nav_title) {
if ($pageHref == $nav_href) {
echo '<li class="active">' . $nav_title . '</li>';
}
else {
echo '<li>' . $nav_title . '</li>';
}
}