织梦园模板网专注于织梦企业模板、DeDe整站模板、织梦Html5模板等织梦模板的下载,提供DEDE织梦模板相关服务。织梦园织梦模板交流群
用户名:
密码:
注册
注册后享受折扣价

dedecms织梦调用三级四级无限级栏目教程

织梦园模板 / 2020-03-05 / 收藏

调用三级四级无限级栏目效果图

dedecms织梦调用三级四级无限级栏目教程

***种自定义函数递归法

适用于前端简单样式用户,在 include/extend.func.php ***下面添加

/**
    * 取出所有分类
    * @param     int   $channel  频道ID
    * @return    string  www.dedeyuan.com
    * 调用{dede:global.getalltype function='getalltype()'/}
    */
  
    function getalltype($channel=0,$line=10)
    {
             $line = empty($line) ? 10 : $line;
             global $dsql,$result;
             
             $dsql->SetQuery("SELECT id,typename,typenamedir,typelitpic,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
                FROM `dede_arctype` WHERE reid='$channel' And ishidden<>1 order by sortrank asc limit 0, $line ");
             $dsql->Execute($channel);
             if($dsql->GetTotalRow($channel)>0)
             {
                       $result .= "<ul>
";
                       while($row = $dsql->GetArray($channel))
                       {
                                $id = $row['id'];
                                $typename = $row['typename'];
                                $typelink = GetOneTypeUrlA($row);
  
                                $result .= "       <li>
";
                                $result .= "                <a href='{$typelink}' target='_blank'>{$typename}</a>
";
                                getalltype($id,$line);
                                $result .= "       </li>
";
                       }
            $result .= "</ul>
";
             }
             return $result;
    }

前台模板调用标签

{dede:global.getalltype function='getalltype()'/}

 

第二种标签嵌套法

适用于只调用出一级、二级、三级、四级的用户,直接在模板里写

<ul>
             {dede:channelartlist row=7 typeid=top}
             <!-- 顶级 -->
             <li>
                       <a href="{dede:field.typeurl/}" >{dede:field name='typename'/}</a>
                       <ul>
                       {dede:channel type=son noself=yes}
                       <!-- 二级 -->
                       <li>
                       <a href="[field:typeurl/]"  title="[field:typename/]">[field:typename/]</a>
                       <ul>
    <!-- 三级 -->
    [field:id runphp=yes]
    global $dsql;
    $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath FROM `dede_arctype` 
    WHERE [email protected] And ishidden<>1 order by sortrank asc limit 0,10";
    $dsql->SetQuery($sql);
    $dsql->Execute('t');
    $result = '';
    while($row = $dsql->GetArray('t'))
    {
        $typename = $row['typename'];
        $typeurl = GetOneTypeUrlA($row);
    $result .= <<< TPL
    <li><a href="{$typeurl}">{$typename}</a></li>
    TPL;
    }
    @me = $result;
    [/field:id]
                       </ul>
                       </li>
                       {/dede:channel}
                       </ul>
             </li>   
             {/dede:channelartlist}
    </ul>


上面的是输出到三级栏目,如果需要四级栏目可以这样写

<!-- 三级/四级 -->
    [field:id runphp=yes]
    global $dsql;
    $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath FROM `dede_arctype` 
    WHERE [email protected] And ishidden<>1 order by sortrank asc limit 0,10";
    $dsql->SetQuery($sql);
    $dsql->Execute('t');
    $result = '';
    while($row = $dsql->GetArray('t'))
    {
        $row['typeurl'] = GetOneTypeUrlA($row);
             $result .= "<a href='{$row[typeurl]}'>{$row[typename]}</a>";
             //四级
             $nsql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath 
             FROM `dede_arctype` WHERE reid=$row[id] And ishidden<>1 order by sortrank asc limit 0,10";
             $dsql->SetQuery($nsql);
             $dsql->Execute('n');
             while($nrow = $dsql->GetArray('n'))
             {
                       $nrow['typeurl'] = GetOneTypeUrlA($nrow);
                       $result .= "<a href='{$nrow[typeurl]}'>{$nrow[typename]}</a>";
             }
    }
    @me = $result;
    [/field:id]

相关站长手记

收缩