0

我有一个带有一些 PHPif语句的 HTML 水平菜单,用于查看链接是否处于活动状态。

这是HTML:

<li<?php if(dirname($_SERVER['REQUEST_URI'])."/" == '/clients/') { echo ' class="current_page_item"'; } ?>><a href="/clients/">Login</a></li>

<li<?php if($_SERVER["REQUEST_URI"] == '/clients/index.php?fuse=support&view=SubmitTicketForm') { echo ' class="current_page_item"'; } ?>><a href="/clients/index.php?fuse=support&view=SubmitTicketForm">Contact Us</a></li>

联系我们链接在客户目录中,登录链接是除了联系我们链接位置之外的整个客户目录,如果当前 URL 在目录中,客户是使登录链接成为活动链接,但我没有希望这发生在联系我们链接上。

我怎样才能解决这个问题?

更新: 我刚刚尝试过http://pastebin.com/ePSQe0i0但它不起作用。它将活动链接保留在 Home 链接上。

4

1 回答 1

1

You check for:

dirname($_SERVER['REQUEST_URI'])."/"

That will always be '/clients/' in both cases.

Why not simply check for:

<li<?php if($_SERVER['REQUEST_URI'] == '/clients/') { echo ' class="current_page_item"'; } ?>><a href="/clients/">Login</a></li>

And leave the second one as it is

Edit

So now I think I understand: Check that '/clients/' is part of $_SERVER['REQUEST_URI'] but also exclude the special case where $_SERVER["REQUEST_URI"] == '/clients/index.php?fuse=support&view=SubmitTicketForm'

So here goes:

<li<?php if((dirname($_SERVER['REQUEST_URI'])."/" == '/clients/')&&(($_SERVER["REQUEST_URI"] != '/clients/index.php?fuse=support&view=SubmitTicketForm'))) { echo ' class="current_page_item"'; } ?>><a href="/clients/">Login</a></li>

<li<?php if($_SERVER["REQUEST_URI"] == '/clients/index.php?fuse=support&view=SubmitTicketForm') { echo ' class="current_page_item"'; } ?>><a href="/clients/index.php?fuse=support&view=SubmitTicketForm">Contact Us</a></li>
于 2013-10-07T19:40:14.713 回答