thinkphp获取栏目和文章当前位置的方法
本篇章节讲解thinkphp获取栏目和文章当前位置的方法。分享给大家供大家参考。具体实现方法如下: 今天把博客一些细节完善了一下,其中修改了一下栏目页和文章页中的“当前位置”。以前栏目很少,就用死办法做的(首页 -> 栏目的名字),现在栏目多了,渐渐二级栏目,三级栏目也来了,这样的方式显然不太合适,于是就改进了一下。也不难,利用一个递归函数就可以了。 测试效果如下图所示: 查看源文件效果: 代码如下: -> -> -> ecshop加入百度地图,支持周边标记
代码如下: assign("now_here",$this->now_here($catid,$res['title']));
//解释一下,栏目表category中的catid为栏目id,catname为栏目名称,asmenu为栏目父级的id,当为顶级栏目时,asmenu为0 。 protected function now_here($catid,$ext=''){ $cat = M("Category"); $here = ''; $uplevels = $cat->field("catid,catname,asmenu")->where("catid=$catid")->find(); if($uplevels['asmenu'] != 0) $here .= $this->get_up_levels($uplevels['asmenu']); $here .= ' -> "; if($ext != '') $here .= ' -> '.$ext; return $here; } protected function get_up_levels($id){ $cat = M("Category"); $here = ''; $uplevels = $cat->field("catid,asmenu")->where("catid=$id")->find(); $here .= ' -> "; if($uplevels['asmenu'] != 0){ $here = $this->get_up_levels($uplevels['asmenu']).$here; } return $here; } 希望本文所述对大家的PHP程序设计有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |