我正在创建一个导航栏,如果页面当前处于活动状态,它会自动将类更改为“活动”(使用 php if 语句 [使用当前 URL 进行匹配])
我还希望能够根据用户是否登录来更改标题...现在我通常对此没有问题,但是,因为变量内部有 if 语句,我不知道如何继续。
我的问题是,如果在变量 estabilsihing 中执行 if 语句是不可能的……例如,这是我正在尝试做的,但是它不起作用……有没有办法做到这一点,并且实际上使它起作用。 ..谢谢你提前!
我的代码
---PHP ---
在头上:
<?php
///// (GETS THE PARTS OF THE CURRENT URL)
error_reporting(0);
$directoryURIbody = $_SERVER['REQUEST_URI'];
$pathbody = parse_url($directoryURIbody, PHP_URL_PATH);
$componentsbody = explode('/', $pathbody);
$first_partsbody = $componentsbody[1];
$second_partsbody = $componentsbody[2];
$third_partsbody = $componentsbody[3];
$fourth_partsbody = $componentsbody[4];
$fifth_partsbody = $componentsbody[5];
?>
在正文中:
:<?php
if (!isset($_SESSION['idx'])) { ///////////IF NOT LOGGED IN
if (!isset($_COOKIE['idCookie'])) {//////IF NOT LOGGED IN
$navbar = '
<li class="<?php if ($first_partmainnav=="") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>">Home</a></li>
<li class="<?php if ($first_partmainnav=="tutorials") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>tutorials">Tutorials</a></li>
<li class="<?php if ($first_partmainnav=="resources") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>resources">Resources</a></li>
<li class="<?php if ($first_partmainnav=="library") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>library">Library</a></li>
<li class="<?php if ($first_partmainnav=="our-projects") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>our-projects">Our Projects</a></li>
<li class="<?php if ($first_partmainnav=="community") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>community">Community</a></li>';
}
if (isset($_SESSION['idx'])) { ////////////IF LOGGED IN (WITHOUT COOKIES)
$navbar = '
<li class="<?php if ($first_partmainnav=="") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>">Home</a></li>
<li class="<?php if ($first_partmainnav=="whatever") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>whatever">whatever</a></li>
<li class="<?php if ($first_partmainnav=="justanother") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>justanother">Just Another</a></li>
';
} else if (isset($_COOKIE['idCookie'])) {//IF LOGGED IN (WITH COOKIES)
$navbar = '
<li class="<?php if ($first_partmainnav=="") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>">Home</a></li>
<li class="<?php if ($first_partmainnav=="whatever") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>whatever">whatever</a></li>
<li class="<?php if ($first_partmainnav=="justanother") {echo "active"; } else {echo "noactive";}?>"><a href="<?php echo $dyn_wwwFULL; ?>justanother">Just Another</a></li>
';
}
?>
<?php echo $navbar; ?>