在我的网站上,我使用开关盒为导航栏的活动链接提供颜色。
$case
我首先在导航栏中声明了一个包含所有可能链接的数组。然后,我检查它是否是在其中一个页面上单击的函数(如果查询字符串不为空)以及它是否被放入$case
数组中(以防止在单击其他页面内的其他链接时改变颜色。)
如果为真,$current
将得到一个值,docs_zamo
或者akuut_wgakuut --> FILENAME_QUERY.
我只想在我之前声明它时更改颜色(在 $case 数组中)否则,它只是文件名(没有'.php')
我发现这段代码相当笨拙。还有其他方法可以完成这项工作吗?我对 PHP 很陌生。我想; 如果有一个函数检查开关内是否存在案例,那么我不需要 $case 数组,因为我已经声明开关案例内存在链接。
检查它是否是 FILENAME_QUERY 链接的代码:
$case = array("index","medica","praesidium","akuut","sponsors","docs","docs_zamo","kalender","evenementen","fotos","werking","jaarraden","akuut_wgakuut","onderwijs","sociaal","sport","werkgroepen","eerstejaars","international",);
if (($_SERVER['QUERY_STRING'] != "") && (in_array(basename($_SERVER['PHP_SELF'],'.php') ."_". str_replace('actie=','',$_SERVER['QUERY_STRING']),$case) == true)) {
$current = basename($_SERVER['PHP_SELF'],'.php') ."_". str_replace('actie=','',$_SERVER['QUERY_STRING']);
}
else {$current = basename($_SERVER['PHP_SELF'],'.php');}
开关:
$id = array("","","","","","","","","","","","","","","","","","","");
switch($current)
{
case $case[0]:$id[0]="class = 'here'";break;
case $case[1]:$id[1]="class = 'here'";break;
case $case[2]:$id[2]="class = 'here'";break;
case $case[3]:$id[3]="class = 'here'";break;
case $case[4]:$id[4]="class = 'here'";break;
case $case[5]:$id[5]="class = 'here'";break;
case $case[6]:$id[18]="class = 'here'";break;
case $case[7]:$id[6]="class = 'here'";break;
case $case[8]:$id[7]="class = 'here'";break;
case $case[9]:$id[8]="class = 'here'";break;
case $case[10]:$id[9]="class = 'here'";break;
case $case[11]:$id[10]="class = 'here'";break;
case $case[12]:$id[11]="class = 'here'";break;
case $case[13]:$id[12]="class = 'here'";break;
case $case[14]:$id[13]="class = 'here'";break;
case $case[15]:$id[14]="class = 'here'";break;
case $case[16]:$id[15]="class = 'here'";break;
case $case[17]:$id[16]="class = 'here'";break;
case $case[18]:$id[17]="class = 'here'";break;
}
?>
的HTML:
<div id='menu'>
<ul>
<li><a href='index.php' <? echo $id[0]; ?>>home</a></li>
<li><a href='medica.php' <? echo $id[1]; ?>>medica</a>
<ul>
<li><a href='praesidium.php' <? echo $id[2]; ?>>» praesidium</a></li>
<li><a href='akuut.php' <? echo $id[3]; ?>>» akuut</a></li>
<li><a href='sponsors.php' <? echo $id[4]; ?>>» sponsors</a></li>
</ul>
</li>
<li><a href='docs.php' <? echo $id[5]; ?>>doc's bar</a>
<ul>
<li><a href='docs.php' <? echo $id[5]; ?>>» doc's</a></li>
<li><a href='docs.php?actie=zamo' <? echo $id[18]; ?>>» zamo</a></li>
</ul>
</li>
<li><a href='kalender.php' <? echo $id[6]; ?>>kalender</a>
<ul>
<li><a href='evenementen.php' <? echo $id[7]; ?>>» evenementen</a></li>
</ul>
</li>
<li><a href='fotos.php' <? echo $id[8]; ?>>foto's</a></li>
<li><a href='werking.php' <? echo $id[9]; ?>>Werking</a>
<ul>
<li><a href='jaarraden.php' <? echo $id[10]; ?>>» jaarraden</a></li>
<li><a href='akuut.php?actie=wgakuut' <? echo $id[11]; ?>>» akuut</a></li>
<li><a href='onderwijs.php' <? echo $id[12]; ?>>» onderwijs</a></li>
<li><a href='sociaal.php' <? echo $id[13]; ?>>» sociaal</a></li>
<li><a href='sport.php' <? echo $id[14]; ?>>» sport</a></li>
<li><a href='werkgroepen.php' <? echo $id[15]; ?>>» werkgroepen</a></li>
</ul>
</li>
<li><a href='eerstejaars.php' <? echo $id[16]; ?>>eerstejaars</a></li>
<li><a href='https://www.medica-csd.be' target='_blank'>cursusdienst</a></li>
<li style='border:none;'><a href='http://www.medica.be/w' target='_blank'>wikimedica</a></li>
<li><a href='international.php' <? echo $id[17]; ?>>international <img src='site/images/gb.png'></a></li>
</ul>
</div>