以前栏目很少,就用死办法做的(首页 -> 栏目的名字),现在栏目多了,渐渐二级栏目,三级栏目也来了,这样的方式显然不太合适,于是就改进了一下。也不难,利用一个递归函数就可以了。
使用例子:
实现代码:
//解释一下,栏目表category中的catid为栏目id,catname为栏目名称,asmenu为栏目父级的id,当为顶级栏目时,asmenu为0 。
protected function now_here($catid,$ext=\'\'){
$cat = M(\"Category\");
$here = \'<a href=\"http://www.phpstudy.net\">首页</a>\';
$uplevels = $cat->field(\"catid,catname,asmenu\")->where(\"catid=$catid\")->find();
if($uplevels[\'asmenu\'] != 0)
$here .= $this->get_up_levels($uplevels[\'asmenu\']);
$here .= \' -> <a href=\"/cat_\'.$uplevels[\'catid\'].\'.html\">\'.$uplevels[\'catname\'].\"</a>\";
if($ext != \'\') $here .= \' -> \'.$ext;
return $here;
}
protected function get_up_levels($id){
$cat = M(\"Category\");
$here = \'\';
$uplevels = $cat->field(\"catid,catname,asmenu\")->where(\"catid=$id\")->find();
$here .= \' -> <a href=\"/cat_\'.$uplevels[\'catid\'].\'.html\">\'.$uplevels[\'catname\'].\"</a>\";
if($uplevels[\'asmenu\'] != 0){
$here = $this->get_up_levels($uplevels[\'asmenu\']).$here;
}
return $here;
}
本文地址:https://www.stayed.cn/item/11025
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我