嗨我有一个导航栏,其中包含两种类型的新闻TOP和Upcoming with subcategories,我有以下代码添加class='current'
当子类别例如来自即将来临的“经济”被选中但当我按下相同的时候类别,但从TOP新闻它无论如何激活即将到来。
<?PHP
$category = $_REQUEST[category];
echo "<ul id='frumos'>";
echo "<li ";
if($category == 'economic'){
echo " class='current'";
}
echo "><a href='/upcoming.php?category=economic'>Economic</a></li> ";
echo "<li";
if($category == 'other'){
echo " class='current'";
}
echo "><a href='/upcoming.php?category=other'>Freestyle</a></li>";
echo "<li";
if($category == 'social'){
echo " class='current'";
}
echo "><a href='/upcoming.php?category=social'>Social</a></li>";
echo "</ul>";
?>
我是PHP的新手,我尝试了这段代码,但它不起作用(原始菜单here)
<?PHP
$category = $_REQUEST[category];
if ($pagename eq 'upcoming')
echo "<ul id='frumos'>";
echo "<li ";
if($category == 'economic'){
echo " class='current'";
}
echo "><a href='/upcoming.php?category=economic'>Economic</a></li> ";
else
echo "<ul id='frumos'>";
echo "<li ";
if($category == 'economic'){
echo " class='current'";
}
echo "><a href='/?category=economic'>Economic</a></li> ";
echo "<li";
if($category == 'other'){
echo " class='current'";
}
echo "><a href='/upcoming.php?category=other'>Freestyle</a></li>";
echo "<li";
if($category == 'social'){
echo " class='current'";
}
echo "><a href='/upcoming.php?category=social'>Social</a></li>";
echo "</ul>";
?>
答案 0 :(得分:0)
你错过了一些牙套。我不确定这是不是你想要的,但它是开始的地方。
<?PHP
$category = $_REQUEST[category];
if ($pagename eq 'upcoming') {
echo "<ul id='frumos'>";
echo "<li ";
if($category == 'economic'){
echo " class='current'";
}
echo "><a href='/upcoming.php?category=economic'>Economic</a></li> ";
} else {
echo "<ul id='frumos'>";
echo "<li ";
if($category == 'economic'){
echo " class='current'";
}
echo "><a href='/?category=economic'>Economic</a></li> ";
echo "<li";
if($category == 'other'){
echo " class='current'";
}
echo "><a href='/upcoming.php?category=other'>Freestyle</a></li>";
echo "<li";
if($category == 'social'){
echo " class='current'";
}
echo "><a href='/upcoming.php?category=social'>Social</a></li>";
}
echo "</ul>";
?>