奋斗的公鸡 發表於 2023-7-27 00:00:00

DedeCms获取任意栏目N级列表链接树形菜单的方法

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        DedeCms获取任意栏目N级列表链接树形菜单,小编提示,下边的修改方法,适用于DedeCMS默认的表前缀,如果你安装的时候修改了,请注意修改。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        在\include\channelunit.func.php文件底部添加如下代码:</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:php;toolbar:false;">
/*树形栏目补充,获取二级,san级,四级栏目列表/

function getProductTree($typeid)

{

$linkList = "";

$dsql = new DedeSql(false);

$dsql-&gt;SetQuery("select ID,typedir,typename,isdefault from dede_arctype where reID = '$typeid' order by sortrank");

$dsql-&gt;Execute();

while($row=$dsql-&gt;GetObject())

{

   $typelink = GetTypeUrl($row-&gt;id,MfTypedir($row-&gt;typedir),$row-&gt;isdefault,$row-&gt;defaultname,$row-&gt;ispart,$row-&gt;namerule2,$row-&gt;moresite,$row-&gt;siteurl,$row-&gt;sitepath);

   $linkList .= "\n&lt;div class=\"firsttype\"&gt;&lt;a href=\"$typelink\"&gt;&lt;b&gt;".$row-&gt;typename."&lt;/b&gt;&lt;/a&gt;&lt;/div&gt;\n\n";

   $linkList .= getSonClass($row-&gt;ID);

}

$dsql-&gt;Close();

return $linkList;

}

//获得小类栏目链接

function getSonClass($parentid)

{

$linkList = "";

$dsql = new DedeSql(false);

$dsql-&gt;SetQuery("Select ID,typedir,typename,isdefault From dede_arctype where reID='$parentid' order by sortrank");

$dsql-&gt;Execute($parentid);

while($row=$dsql-&gt;GetObject($parentid))

{

   $typelink = GetTypeUrl($row-&gt;id,MfTypedir($row-&gt;typedir),$row-&gt;isdefault,$row-&gt;defaultname,$row-&gt;ispart,$row-&gt;namerule2,$row-&gt;moresite,$row-&gt;siteurl,$row-&gt;sitepath);

   $linkList .= "&lt;li class=\"secondtype\"&gt;&lt;a href=\"$typelink\"&gt;".$row-&gt;typename."&lt;/a&gt;&lt;/li&gt;\n";

   $linkList .= getSonClass2($row-&gt;ID);

}

return $linkList;

}

function getSonClass2($parentid)

{

$linkList = "";

$dsql = new DedeSql(false);

$dsql-&gt;SetQuery("Select ID,typedir,typename,isdefault From dede_arctype where reID='$parentid' order by sortrank");

$dsql-&gt;Execute($parentid);

while($row=$dsql-&gt;GetObject($parentid))

{

   $typelink = GetTypeUrl($row-&gt;id,MfTypedir($row-&gt;typedir),$row-&gt;isdefault,$row-&gt;defaultname,$row-&gt;ispart,$row-&gt;namerule2,$row-&gt;moresite,$row-&gt;siteurl,$row-&gt;sitepath);

   $linkList .= "&lt;li class=\"thirdtype\"&gt;&lt;a href=\"$typelink\"&gt;".$row-&gt;typename."&lt;/a&gt;&lt;/li&gt;\n";

   $linkList .= getSonClass3($row-&gt;ID);

}

return $linkList;

}

function getSonClass3($parentid)

{

$linkList = "";

$dsql = new DedeSql(false);

$dsql-&gt;SetQuery("Select ID,typedir,typename,isdefault From dede_arctype where reID='$parentid' order by sortrank");

$dsql-&gt;Execute($parentid);

while($row=$dsql-&gt;GetObject($parentid))

{

   $typelink = GetTypeUrl($row-&gt;id,MfTypedir($row-&gt;typedir),$row-&gt;isdefault,$row-&gt;defaultname,$row-&gt;ispart,$row-&gt;namerule2,$row-&gt;moresite,$row-&gt;siteurl,$row-&gt;sitepath);

   $linkList .= "&lt;li class=\"fourthtype\"&gt;&lt;a href=\"$typelink\"&gt;".$row-&gt;typename."&lt;/a&gt;&lt;/li&gt;\n";

}

return $linkList;

}
/*树形栏目补充*/
</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        2、在模板里用</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:xhtml;">
{dede:channel function='getProductTree(2)'}{/dede:channel} 
</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        调用即可。这里getProductTree(2)中的 2 是产品展示的栏目ID。如果你的是其他的,请作相应修改。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。</p>
頁: [1]
查看完整版本: DedeCms获取任意栏目N级列表链接树形菜单的方法