织梦DeDeCMS在模板(列表与内容页)中获取顶级栏目ID,这个我们常用到做频道图片时,他就非常实用了。
如你某个栏目的要做banner或其他的,只要素材上加上一个数字就完全是用到它了。
打开 /include/taglib/type.lib.php ,找到
$row
=
$dsql
->GetOne(
"Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath From zmb_arctype where id='$typeid' "
);
在可选择的字段里面增加topid字段,如下
$row
=
$dsql
->GetOne(
"Select id,topid,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath From zmb_arctype where id='$typeid' "
);
紧接着找到
if
(!
is_array
(
$row
))
return
''
;
在下面添加一行新的代码,如下:
if
(!
is_array
(
$row
))
return
''
;
if
(
$row
[
'topid'
]==0){
$row
[
'topid'
]=
$row
[
'id'
];}
对源代码的修改至此完成,在模板中的调用方法为{dede:type}[field:topid /]{/dede:type}
这样无论是在频道页、列表页还是文章页都可以轻而易举地获取到当前顶级栏目ID了,对于需要把顶级栏目ID作为参数传递给自定义函数的朋友及其方便。
这样无论是在频道页、列表页还是文章页都可以轻而易举地获取到当前顶级栏目ID了,对于需要把顶级栏目ID作为参数传递给自定义函数的朋友及其方便。