帝国cms同时调用一级、二级栏目并当前栏目高亮显示的方法
今天用帝国cms出现了需要同时调用1,2级栏目并给当前栏目高亮显示的需求,经过一番搜索,用以下代码即可实现(包含首页高亮) 而且可以无限嵌套
< nav > < ul id = "show" > < li <?=$GLOBALS[navclassid]==0?" class = 'on' ":""?>>< a href = "[!--news.url--]" >Home</ a ></ li > [e:loop={"select classid,classname,islast from {$dbtbpre}enewsclass where bclassid='0' and showclass=0 order by myorder,classid ASC limit 11",0,24,0}] <? php $ classurl = sys_ReturnBqClassname ($bqr,9);//取得栏目地址 $ class = "" ; if($GLOBALS[navclassid]) { $ fcr = explode ('|',$class_r[$GLOBALS[navclassid]][featherclass]); $topbclassid=$fcr[1]?$fcr[1]:$GLOBALS[navclassid];//取得当前栏目的一级栏目ID if($bqr[classid]==$topbclassid) { $ class = " class='on'" ; } } ?>< li <?=$class?>>< a href="<?=$classurl?>">< span ><?=$bqr[classname]?></ span ></ a ><? php if(!$bqr[islast]) //判断是否终极栏目 { ?>< div class = "menu" > <? php //取得栏目下的子栏目 $newsclass=$empire->query("select classid,classname from ".$dbtbpre."enewsclass where bclassid=".$bqr[classid]." order by myorder,classid desc limit 11"); while($classr=$empire->fetch($newsclass)) { $classrurl=sys_ReturnBqClassname($classr,9); //取得子栏目地址 ?>< div class = "item" >< a href="<?=$classrurl?>"><?=$classr[classname]?></ a ></ div > <? php } ?></ div ><? php } ?></ li > [/e:loop] </ ul > </ nav > |
另一种写法
<nav> <ul id= "show" > <ul class = "w-f" > <li<?= $GLOBALS [navclassid]==0? " class='on'" : "" ?>> <a href= "#" >首页</a> </li> [e:loop={ "select classid,classname from {$dbtbpre}enewsclass where bclassid=0 and classid<>17 order by myorder,classid asc" ,0,24,0}] <?php $classurl =sys_ReturnBqClassname( $bqr ,9); //取得栏目地址 $class = "" ; if ( $GLOBALS [navclassid]) { $fcr = explode ( '|' , $class_r [ $GLOBALS [navclassid]][featherclass]); $topbclassid = $fcr [1]? $fcr [1]: $GLOBALS [navclassid]; //取得当前栏目的一级栏目ID if ( $bqr [classid]== $topbclassid ) { $class = " class='on'" ; } } ?> <li<?= $class ?>> <a href= "<?=$classurl?>" class = "tit link" ><?= $bqr [classname]?></a> <div class = "menu" > <?php $ecms_bq_sql2 =sys_ReturnEcmsLoopBq( "select classid,classname,classpath,classurl from [!db.pre!]enewsclass where bclassid='$bqr[classid]' order by myorder limit 10" ,20,24,0); $bqno2 =0; while ( $bqr2 = $empire ->fetch( $ecms_bq_sql2 )) { $bqsr2 =sys_ReturnEcmsLoopStext( $bqr2 ); $bqno2 ++; ?> <a href= "/<?=$bqr2[classpath]?>/" ><?= $bqr2 [classname]?></a> <?php } ?> </div> </li> [/e:loop] </ul> </nav> |
html
< nav > < ul id = "show" > < li class = "on" >< a href = "index.html" title = "" >Home</ a ></ li > < li >< a href = "about.html" title = "" >About us</ a ></ li > < li >< a href = "products.html" title = "" >Products</ a > < div class = "menu" > < a href = "" >bearing</ a > < a href = "" >tools</ a > </ div > </ li > < li >< a href = "news.html" title = "" >News</ a ></ li > < li >< a href = "faq.html" title = "" >FAQ</ a ></ li > < li >< a href = "application.html" title = "" >Application</ a ></ li > < li >< a href = "service.html" title = "" >Service</ a ></ li > < li >< a href = "contact.html" title = "" >Contact</ a ></ li > </ ul > </ nav > |
拓展
如果是当前栏目是on 是首页class是menuo
if ( $bqr [classid]== $topbclassid ) { $class = "on" ; } } elseif ( $public_r [home]==1) { $class = "menuo" ; } |
23.02.20拓展,以上只支持一级栏目高亮,二级栏目高亮用这个
< ul class = "accordion" > [e:loop={"select classid,classname from {$dbtbpre}enewsclass where bclassid=2 and classid<>17 order by myorder,classid asc",0,24,0}] <? php $ classurl = sys_ReturnBqClassname ($bqr,9);//取得栏目地址 $ class = "" ; if($bqr[classid]==$GLOBALS[navclassid])//当前栏目ID { $ class = " class='on'" ; } ?> < li <?=$class?>> < div class = "links" >< a href="<?=$classurl?>"><?=$bqr[classname]?></ a ></ div > < ul class = "submenu" style = "display: block;" > <? php $ ecms_bq_sql2 = sys_ReturnEcmsLoopBq ("select classid,classname,classpath,classurl from [!db.pre!]enewsclass where bclassid = '$bqr[classid]' order by myorder limit 10",20,24,0); $ bqno2 = 0 ; while($bqr2=$empire->fetch($ecms_bq_sql2)) { $bqsr2=sys_ReturnEcmsLoopStext($bqr2); $bqno2++; ?> < li <?=$class2?>>< a href="/<?=$bqr2[classpath]?>/"><?=$bqr2[classname]?></ a ></ li > <? php } ?> </ ul > </ li > [/e:loop]</ ul > |