dedecms二次开发:获取任意栏目N级列表链接树形菜单

2015-05-14 00:17 阅读 99 次 评论关闭

在\include\channelunit.func.php文件底部添加如下代码:
-----------------------------------------------------
/*树形栏目补充,获取二级,san级,四级栏目列表/
function getProductTree($typeid)
{
$linkList = "";
$dsql = new DedeSql(false);
$dsql->SetQuery("select ID,typedir,typename,isdefault from dede_arctype where reID = '$typeid' order by sortrank");
$dsql->Execute();
while($row=$dsql->GetObject())
{
$typelink = GetTypeUrl($row->id,MfTypedir($row->typedir),$row->isdefault,$row->defaultname,$row->ispart,$row->namerule2,$row->moresite,$row->siteurl,$row->sitepath);
$linkList .= "\n<div class=\"firsttype\"><a href=\"$typelink\"><b>".$row->typename."</b></a></div>\n\n";
$linkList .= getSonClass($row->ID);
}
$dsql->Close();
return $linkList;
}
//获得小类栏目链接
function getSonClass($parentid)
{
$linkList = "";
$dsql = new DedeSql(false);
$dsql->SetQuery("Select ID,typedir,typename,isdefault From dede_arctype where reID='$parentid' order by sortrank");
$dsql->Execute($parentid);
while($row=$dsql->GetObject($parentid))
{
$typelink = GetTypeUrl($row->id,MfTypedir($row->typedir),$row->isdefault,$row->defaultname,$row->ispart,$row->namerule2,$row->moresite,$row->siteurl,$row->sitepath);
$linkList .= "<li class=\"secondtype\"><a href=\"$typelink\">".$row->typename."</a></li>\n";
$linkList .= getSonClass2($row->ID);
}
return $linkList;
}
function getSonClass2($parentid)
{
$linkList = "";
$dsql = new DedeSql(false);
$dsql->SetQuery("Select ID,typedir,typename,isdefault From dede_arctype where reID='$parentid' order by sortrank");
$dsql->Execute($parentid);
while($row=$dsql->GetObject($parentid))
{
$typelink = GetTypeUrl($row->id,MfTypedir($row->typedir),$row->isdefault,$row->defaultname,$row->ispart,$row->namerule2,$row->moresite,$row->siteurl,$row->sitepath);
$linkList .= "<li class=\"thirdtype\"><a href=\"$typelink\">".$row->typename."</a></li>\n";
$linkList .= getSonClass3($row->ID);
}
return $linkList;
}
function getSonClass3($parentid)
{
$linkList = "";
$dsql = new DedeSql(false);
$dsql->SetQuery("Select ID,typedir,typename,isdefault From dede_arctype where reID='$parentid' order by sortrank");
$dsql->Execute($parentid);
while($row=$dsql->GetObject($parentid))
{
$typelink = GetTypeUrl($row->id,MfTypedir($row->typedir),$row->isdefault,$row->defaultname,$row->ispart,$row->namerule2,$row->moresite,$row->siteurl,$row->sitepath);
$linkList .= "<li class=\"fourthtype\"><a href=\"$typelink\">".$row->typename."</a></li>\n";
}
return $linkList;
}
/*树形栏目补充*/
----------------------------------------------------------------------------
在模板里用
{dede:channel function='getProductTree(2)'}{/dede:channel}
调用即可。这里 getProductTree(2)中的 2 是产品展示的栏目ID。如果你的是其他的,请作相应修改。

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:dedecms二次开发:获取任意栏目N级列表链接树形菜单 | 猎微网

评论已关闭!