最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
thinkphp中获取栏目和文章的当前位置
时间:2022-06-25 02:33:17 编辑:袖梨 来源:一聚教程网
今天把博客一些细节完善了一下,其中修改了一下栏目页和文章页中的“当前位置”。以前栏目很少,就用死办法做的(首页 -> 栏目的名字),现在栏目多了,渐渐二级栏目,三级栏目也来了,这样的方式显然不太合适,于是就改进了一下。也不难,利用一个递归函数就可以了。
测试效果
查看源文件效果:首页 -> PHP学习 -> ecshop -> ecshop二次开发 -> ecshop加入百度地图,支持周边标记
| 代码如下 | 复制代码 |
|
$this->assign("now_here",$this->now_here($catid,$res['title']));
//解释一下,栏目表category中的catid为栏目id,catname为栏目名称,asmenu为栏目父级的id,当为顶级栏目时,asmenu为0 。
$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 .= ' -> '.$uplevels['catname'].""; 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 .= ' -> '.$uplevels['catname'].""; if($uplevels['asmenu'] != 0){ $here = $this->get_up_levels($uplevels['asmenu']).$here; } return $here; } |
|
相关文章
- 《波西亚时光》试炼遗迹赠送武器一览 05-04
- qq网页版快捷登录-QQ官网登录入口 05-04
- 人生四大幸事表情包 05-04
- 2023淘宝618每日一猜7月5日答案一览 05-04
- 天堂漫画comic官方入口-天堂漫画comic官网地址 05-04
- 你终于回消息了骷髅表情包 05-04
