两种Dede织梦调用无限级栏目方法

  253 次阅读

CONTENT

第一种自定义函数递归法:
适用于前端简单样式用户,在 include/extend.func.php 最下面添加

  1. /**
  2.     * 取出所有分类
  3.     * @param     int   $channel  频道ID
  4.     * @return    string
  5.     * 调用{dede:global.getalltype function='getalltype()'/}
  6.     */
  7.  
  8.     function getalltype($channel=0,$line=10)
  9.     {
  10.     	$line = empty($line) ? 10 : $line;
  11.     	global $dsql,$result;
  12.  
  13.     	$dsql->SetQuery("SELECT id,typename,typenamedir,typelitpic,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
  14.                 FROM `dede_arctype` WHERE reid='$channel' And ishidden<>1 order by sortrank asc limit 0, $line ");
  15.     	$dsql->Execute($channel);
  16.     	if($dsql->GetTotalRow($channel)>0)
  17.     	{
  18.     		$result .= "<ul>\r\n"; 
  19.     		while($row = $dsql->GetArray($channel))
  20.     		{
  21.     			$id = $row['id'];
  22.     			$typename = $row['typename'];
  23.     			$typelink = GetOneTypeUrlA($row);
  24.  
  25.     			$result .= "	<li>\r\n";
  26.     			$result .= "		<a href='{$typelink}' target='_blank'>{$typename}</a>\r\n";
  27.     			getalltype($id,$line);
  28.     			$result .= "	</li>\r\n";
  29.     		}
  30.             $result .= "</ul>\r\n";
  31.     	}
  32.     	return $result;
  33.     }

前台模板调用标签

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

第二种标签嵌套法:
适用于只调用出一级、二级、三级、四级的用户,直接在模板里写

  1. <ul>
  2.     	{dede:channelartlist row=7 typeid=top}
  3.     	<!-- 顶级 -->
  4.     	<li class="top">
  5.     		<a href="{dede:field.typeurl/}" >{dede:field name='typename'/}</a>
  6.     		<ul class="sub">
  7.     		{dede:channel type=son noself=yes}
  8.     		<!-- 二级 -->
  9.     		<li>
  10.     		<a href="[field:typeurl/]"  title="[field:typename/]">[field:typename/]</a>
  11.     		<ul>
  12.     <!-- 三级 -->
  13.     [field:id runphp=yes]
  14.     global $dsql;
  15.     $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath FROM `dede_arctype` WHERE reid=@me And ishidden<>1 order by sortrank asc limit 0,10";
  16.     $dsql->SetQuery($sql);
  17.     $dsql->Execute('t');
  18.     $result = '';
  19.     while($row = $dsql->GetArray('t'))
  20.     {
  21.         $typename = $row['typename'];
  22.         $typeurl = GetOneTypeUrlA($row);
  23.     $result .= <<< TPL
  24.     <li><a href="{$typeurl}">{$typename}</a></li>
  25.     TPL;
  26.     }
  27.     @me = $result;
  28.     [/field:id]
  29.     		</ul>
  30.     		</li>
  31.     		{/dede:channel}
  32.     		</ul>
  33.     	</li>    
  34.     	{/dede:channelartlist}
  35.     </ul>

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

  1. <!-- 三级/四级 -->
  2.     [field:id runphp=yes]
  3.     global $dsql;
  4.     $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath FROM `dede_arctype` WHERE reid=@me And ishidden<>1 order by sortrank asc limit 0,10";
  5.     $dsql->SetQuery($sql);
  6.     $dsql->Execute('t');
  7.     $result = '';
  8.     while($row = $dsql->GetArray('t'))
  9.     {
  10.         $row['typeurl'] = GetOneTypeUrlA($row);
  11.     	$result .= "<a href='{$row[typeurl]}'>{$row[typename]}</a>";
  12.     	//四级
  13.     	$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";
  14.     	$dsql->SetQuery($nsql);
  15.     	$dsql->Execute('n');
  16.     	while($nrow = $dsql->GetArray('n'))
  17.     	{
  18.     		$nrow['typeurl'] = GetOneTypeUrlA($nrow);
  19.     		$result .= "<a href='{$nrow[typeurl]}'>{$nrow[typename]}</a>";
  20.     	}
  21.     }
  22.     @me = $result;
  23.     [/field:id]

Comments | NOTHING

暂无评论...