Php 当前页面高亮按钮

Php 当前页面高亮按钮,php,html,css,Php,Html,Css,我有3个按钮,在我的网站头PHP文件。当您在该页面上时,我想更改按钮的颜色,但我无法使其正常工作,因此我尝试使用$thispage语句来调用它,因此如果它在其中一个页面上,它会添加id=“currentpage”。以下是我使用的代码 <input type='button' value='AVAILABLE NOW' onClick='location="/category/upcoming/"' <?php if ($thisPage) echo " id=\"currentpag

我有3个按钮,在我的网站头PHP文件。当您在该页面上时,我想更改按钮的颜色,但我无法使其正常工作,因此我尝试使用$thispage语句来调用它,因此如果它在其中一个页面上,它会添加id=“currentpage”。以下是我使用的代码

<input type='button' value='AVAILABLE NOW' onClick='location="/category/upcoming/"' <?php if ($thisPage) echo " id=\"currentpage\""; ?> class="header-image" />
<input type='button' value='COMING SOON' onClick='location="/category/soon/"' <?php if ($thisPage) echo " id=\"currentpage\""; ?>class="header-image" />
<input type='button' value='VAULT ARCHIVE' onClick='location="/category/previous/"' <?php if ($thisPage) echo " id=\"currentpage\""; ?>class="header-image" />
class=“标题图像”/>
PHP


if($thisPage)
这些应该像
if($thisPage==“page_x.php”)
这样读,我们不知道您将该变量指定为。添加
currentpage
作为类,而不是
id
作为id是唯一的。
<?php
$page_name = basename(__FILE__);
?>
 <li <?php echo ($page_name == 'page1.php' ? 'class="currentpage"' : 'class="h"'); ?>><a href="whatever.php"> Link1</a></li>
 <li <?php echo ($page_name == 'page2.php' ? 'class="currentpage"' : 'class="h"'); ?>><a href="whatever.php"> Page 2</a></li>
.currentpage{
/*Format it how you want it */
}