gpt4 book ai didi

PHP with or logical 并向 li 全局导航添加一个类

转载 作者:太空宇宙 更新时间:2023-11-04 02:51:36 25 4
gpt4 key购买 nike

我正在使用 PHP 将所有页面上的导航栏覆盖到全局导航。我还使用 PHP 添加类并显示当前页面。

我面临的挑战是父导航选择。当它在子页面上并且子导航也被选中时,它带有下划线。比如我在“历史”页面,子页面到“关于我们”页面。两者都带有下划线。

我面临的挑战是,当我移至下一页“服务区域”或其任何子页面时,“关于我们”导航选项仍然带有下划线。我正在尝试使用 ||防止这种情况发生的逻辑。

下面是下面的代码:

<li class="dropdown <?php if ($thisPage=='About Us'||'History'||'Mission Values'||'Process'||'Our People'||'Testimonials'||'Capstone Cares') echo 'active'; ?>">

当我在不同的导航部分时,有什么方法可以取消选择父导航吗?

网站是http://capstone.dgpehrson.com

这是剩下的代码...

在我添加的各个页面上:

<?php $thisPage="About Us"; ?>

我正在根据页面更改名称。

这是导航代码:

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown <?php if ($thisPage=='About Us' || 'History' || 'Mission Values' || 'Process' || 'Our People' || 'Testimonials' || 'Capstone Cares') echo 'active'; ?>">
<a href="/about.php" class="dropdown-toggle">About Us<span class="caret"></span></a> <!-- Alink extentions that's been removed: data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" -->
<ul class="dropdown-menu">
<li <?php if ($thisPage=="History") echo "class=\"active\""; ?>><a href="/about-history.php">History</a></li>
<li <?php if ($thisPage=="Mission Values") echo "class=\"active\""; ?>><a href="/about-mission.php">Mission &amp; Values</a></li>
<li <?php if ($thisPage=="Process") echo "class=\"active\""; ?>><a href="/about-process.php">Process</a></li>
<li <?php if ($thisPage=="Our People") echo "class=\"active\""; ?>><a href="/about-ourpeople.php">Our People</a></li>
<li <?php if ($thisPage=="Testimonials") echo "class=\"active\""; ?>><a href="/about-testimonials.php">Testimonials</a></li>
<li <?php if ($thisPage=="Capstone Cares") echo "class=\"active\""; ?>><a href="/about-capstone-cares.php">Capstone Cares</a></li>
</ul>
</li>
<li class="dropdown <?php if ($thisPage=='Service Areas'||'Apartments'||'Capital'||'Development Services'||'Manufactured Housing'||'Complimentary') echo 'active'; ?>">
<a href="/service-areas.php">Service Areas<span class="caret"></span></a> <!-- Alink extentions that's been removed: data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" -->
<ul class="dropdown-menu">
<li <?php if ($thisPage=="Apartments") echo "class=\"active\""; ?>><a href="/service-apartments.php">Apartments</a></li>
<li <?php if ($thisPage=="Capital") echo "class=\"active\""; ?>><a href="/service-capital.php">Capital</a></li>
<li <?php if ($thisPage=="Development Services") echo "class=\"active\""; ?>><a href="/service-land.php">Developement Services</a></li>
<li <?php if ($thisPage=="Manufactured Housing") echo "class=\"active\""; ?>><a href="/service-manufactured.php">Manufactured Housing</a></li>
<li <?php if ($thisPage=="Complimentary") echo "class=\"active\""; ?>><a href="/service-value.php">Complimentary Value Analysis</a></li>
</ul>
</li>
<li class="dropdown">
<a href="/offerings.php">Offerings<span class="caret"></span></a> <!-- Alink extentions that's been removed: data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" -->
<ul class="dropdown-menu">
<li><a href="/offerings-apartment.php">Apartment</a></li>
<li><a href="/offerings-manufactured.php">Manufactured Housing</a></li>
<li><a href="/offerings-multi-family.php">Multi-family Land</a></li>
</ul>
</li>
<li class="dropdown">
<a href="/market-reports.php">Market Reports<span class="caret"></span></a> <!-- Alink extentions that's been removed: data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" -->
<ul class="dropdown-menu">
<li><a href="/market-florida.php">Florida</a></li>
<li><a href="/market-kentucky.php">Kentucky</a></li>
<li><a href="/market-ncarolina.php">North Carolina</a></li>
<li><a href="/market-scarolina.php">South Carolina</a></li>
<li><a href="/market-tennessee.php">Tennessee</a></li>
<li><a href="/market-virginia.php">Virginia</a></li>
</ul>
</li>
<li><a href="/news.php">News</a></li>
<li><a href="/careers.php">Careers</a></li>
<li><a href="/contact.php">Contact Us</a></li>
</ul>

最佳答案

您必须比较每个“或”。该字符串正在评估为真。

if ($thisPage=='About Us'||$thisPage=='History'||$thisPage=='Mission Values'||$thisPage=='Process'||$thisPage=='Our People'||$thisPage=='Testimonials'||$thisPage=='Capstone Cares') echo 'active';

关于PHP with or logical 并向 li 全局导航添加一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32895857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com