dedecms 栏目树形无限级菜单实现方法

作者:袖梨 2022-06-25

在includechannelunit.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 .= "nnn";
   $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 .= "
  • ".$row->typename."
  • 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 .= "
  • ".$row->typename."
  • 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 .= "
  • ".$row->typename."
  • n";
    }
    return $linklist;
    }

    /*树形栏目补充*/
    ----------------------------------------------------------------------------
    2、在模板里用

    {dede:channel function='getproducttree(2)'}{/dede:channel} 

    调用即可。这里getproducttree(2)中的 2 是产品展示的栏目id。如果你的是其他的,请作相应修改。

     

    相关文章

    精彩推荐