织梦CMS调用所有栏目一级二级三级和无限级栏

网站建设 2022-07-27 08:13www.1681989.com免费网站
一级、二级、三级、四级标签嵌套法 ul {dede:channelartlist row=7 typeid=} !-- 顶级 -- li class = a href = {dede:field.typeurl/} {dede:field name=typename/} / a ul class = sub {dede:channel type=son noself=yes} !-- 二级 -- li a href = [field:typeurl/] title = [field:type […]



一级、二级、三级、四级标签嵌套法

<ul>
	{dede:channelartlist row=7 typeid=}
	<!-- 顶级 -->
	<li class="">
		<a href="{dede:field.typeurl/}" >{dede:field name='typename'/}</a>
		<ul class="sub">
		{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 `58pic_arctype` WHERE reid=@me 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 .= "<li><a href='{$typeurl}'>{$typename}</a></li>";
				}
				@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 `58pic_arctype` WHERE reid=@me 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 `58pic_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]

无限级栏目无限分类自定义函数递归法

在 clude/extend.func.php 最下面添加

/
 取出所有分类
 @param     t   $channel  频道ID
 @return    strg
 调用{dede:global.getalltype function='getalltype()'/}
/

function getalltype($channel=0,$le=10)
{
	$le = empty($le) ? 10 : $le;
	global $dsql,$result;
	
	$dsql->SetQuery("SELECT id,typename,typenamedir,typelitpic,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
            FROM `58pic_arctype` WHERE reid='$channel' And ishidden<>1 order by sortrank asc limit 0, $le ");
	$dsql->Execute($channel);
	if($dsql->GetTotalRow($channel)>0)
	{
		$result .= "<ul>\r\n"; 
		while($row = $dsql->GetArray($channel))
		{
			$id = $row['id'];
			$typename = $row['typename'];
			$typelk = GetOneTypeUrlA($row);

			$result .= "	<li>\r\n";
			$result .= "		<a href='{$typelk}' target='_blank'>{$typename}</a>\r\n";
			getalltype($id,$le);
			$result .= "	</li>\r\n";
		}
        $result .= "</ul>\r\n";
	}
	return $result;
}

前台模板调用标签

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


Copyright © 2016-2025 www.1681989.com 推火网 版权所有 Power by