Home >php教程 >php手册 >dedecms获取多级栏目

dedecms获取多级栏目

WBOY
WBOYOriginal
2016-06-06 19:35:381007browse

把函数getall放到include文件夹下的extend.func.php文件里面 DeDeCMS function getall($id){ global $dsql;$sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath FROM `dede_arctype` WHERE reid=$id order

把函数getall放到include文件夹下的extend.func.php文件里面
DeDeCMS
function getall($id){
    global $dsql;
	$sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath FROM `dede_arctype` WHERE reid=$id order by sortrank asc";
	$dsql->SetQuery($sql);
	$dsql->Execute();
	while($row = $dsql->GetArray()) {
		$row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
		$arrs[] = $row;
	}
	for($i=0;$i<count($arrs);$i++){
        $row2 = $dsql->GetOne("SELECT id FROM `dede_arctype` WHERE reid='$arrs[$i][id]'");
		if($row2['id'] > 0){
			$arrs[$i]['son'] = getall($arrs[$i]['id']);
		}
	}
	return $arrs;
}
//下面是模板代码,可自定义
{dede:php}
$res = getall(5);
$html = '';
for($i=0;$i<count($res);$i++){
    $html .="<li class='dm_on'><a onclick='dm_sidenav(\"mua".$res[$i][id]."\",this)' href='###' rurl='".$res[$i][typeurl]."'>".$res[$i][typename]."</a>";
		if(!empty($res[$i][son])){
        	$lv2 = $res[$i][son];
            $html .="<ul id='mua".$res[$i][id]."'>";
            for($j=0;$j<count($lv2);$j++){
              $html .="<li><a onclick='dm_sidenav(\"muoa".$lv2[$j][id]."\",this)' rurl='".$lv2[$j][typeurl]."'>".$lv2[$j][typename]."</a>";
              	  if(!empty($lv2[$j][son])){
                     $lv3 = $lv2[$j][son];
                     $html .="<ul id='muoa".$lv2[$j][id]."' style='display:none;'>";
                     	for($u=0;$u<count($lv3);$u++){
                            $html .="<li><a href='".$lv3[$u][typeurl]."'>".$lv3[$u][typename]."</a> </li>";
                        }
                     $html .="</ul>";
                  }
             $html .="</li>";
          	}
            $html .='</ul>';
         }
    $html .='</li>';
}
echo $html;
{/dede:php}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:简单的实现微信平台开发Next article:php导出excel