两种方法,推荐第二种!

第一种方法


<div class=”catleader minicat”>

<ul class=”sub-category”>

<?php

$bclassid = $class_r[$GLOBALS[navclassid]][bclassid]; //获取当前父栏目ID

$cr[‘classid’]=$class_r[$GLOBALS[navclassid]][bclassid];

$bclassurl=sys_ReturnBqClassname($cr,9);

?>

<li class=”cat-item”> <a href=”<?=$bclassurl?>”>全部</a> </li>

[e:loop={“select classid,classname from {$dbtbpre}enewsclass where bclassid=’$bclassid’ order by myorder,classid asc”,0,24,0}]

<?

$classurl=sys_ReturnBqClassname($bqr,9);//取得栏目地址

$on=””;

if($bqr[classid]==$GLOBALS[navclassid])//当前栏目ID

{

$on=”current-cat”;

}

?>

<li class=”cat-item <?=$on?>”> <a href=”<?=$classurl?>”><?=$bqr[classname]?></a> </li>

[/e:loop]

</ul>

</div>

第二种方法:


<?php

$bclassid = $class_r[$GLOBALS[navclassid]][bclassid]; //获取当前父栏目ID

if($bclassid!=0){

$cr[‘classid’]=$class_r[$GLOBALS[navclassid]][bclassid];

$bclassurl=sys_ReturnBqClassname($cr,9);

}else{

//父级栏目

$bclassurl=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);

$bclassid=$GLOBALS[navclassid];

}

?>

<li ><a href=”<?=$bclassurl;?>” id=”nav<?=$bclassid?>”>全部</a></li>

[e:loop={“select * from `[!db.pre!]enewsclass` where bclassid=’$bclassid’ order by myorder,classid asc “,0,24,0,0,0}]

<li><a href=”<?=$bqsr[classurl]?>” id=”nav<?=$bqr[classid]?>”><?=$bqr[classname]?></a></li>

[/e:loop]

<script>

$(document).ready(function(){

$(“#nav[!–self.classid–]”).addClass(“active”);

});

</script>