使用php url hilighing当前导航选项卡,带有和不带.php扩展名
//php code
function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
$Current=curPageName();;
?>
// HTML,CSS
<li id=<?php if ("index.php"==$Current) echo "selected";else echo "";?>>
答案 0 :(得分:1)
相反,我使用这样的东西将当前页面作为导航栏中的活动菜单:
$page = "page_name"
放入您的网页,例如home page
,将其设为$page = "home"
<li <?php echo ($page == 'home') ? "class='active'" : ""; ?> title="Home Page"><a href="<?php echo BASE_URL; ?>">Home</a></li>
<li <?php echo ($page == 'article') ? "class='active'" : ""; ?> title="Recent articles"><a href="<?php echo BASE_URL; ?>/articles">Articles</a></li>
...
...
active
类以达到预期效果。答案 1 :(得分:1)
希望有所帮助
<?php
function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
$Current=curPageName();
$nav_tabs=array('home','about','products','contacts');
foreach($nav_tabs as $nav)
{
if($nav == $current)
{
echo"<li class='active' > <a href='$nav' > $nav </a></li>";
}
else
{
echo"<li > <a href='$nav' > $nav </a></li>";
}
}
?>
//在CSS中定义active以突出显示选项卡
.active{
background-color:black;
font-white;
}