织梦调用四级子栏目,首先需要修改文件:\include\taglib\channel.lib.php,请将以下代码全部复制替换上述文件:
001<?php 002function lib_channel(&$ctag,&$refObj) 003{ 004global $_sys_globals,$envs,$dsql; 005$attlist = "typeid|0,reid|0,row|100,col|1,type|son,currentstyle|"; 006FillAttsDefault($ctag->CAttribute->Items,$attlist); 007extract($ctag->CAttribute->Items, EXTR_SKIP); 008$innertext = $ctag->GetInnerText(); 009$cacheid = trim($cacheid); 010if($cacheid !='') { 011$likeType = GetCacheBlock($cacheid); 012if($likeType != '') return $likeType; 013} 014 015$reid = 0; 016$topid = 0; 017if(empty($typeid) && $envs['typeid']!=0) 018{ 019$typeid = $envs['typeid']; 020$reid = $envs['reid']; 021}else{ 022$reid=0; 023} 024if($type==''||$type=='sun') $type="son"; 025if($innertext=='') $innertext = GetSysTemplets("channel_list.htm"); 026if($reid==0 && $typeid>0) 027{ 028$dbrow = $dsql->GetOne("Select reid From dede_arctype where id='$typeid' "); 029if(is_array($dbrow)) $reid = $dbrow['reid']; 030} 031$likeType = ''; 032if($type=='top') 033{ 034$sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description 035From dede_arctype where reid=0 And ishidden<>1 order by sortrank asc limit 0,$row"; 036} 037else if($type=="son") 038{ 039//if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid']; 040if($typeid==0) { 041return ''; 042} 043$sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description 044From dede_arctype where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row"; 045} 046else if($type=="self") 047{ 048if($reid==0) { 049return ''; 050} 051$sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description 052From `dede_arctype` where reid='$reid' And ishidden<>1 order by sortrank asc limit 0,$row"; 053} 054//And id<>'$typeid' 055$needRel = false; 056$dtp2 = new DedeTagParse(); 057$dtp2->SetNameSpace("field","[","]"); 058$dtp2->LoadSource($innertext); 059$dsql2 = clone $dsql; 060$dsql->SetQuery($sql); 061$dsql->Execute(); 062$line = $row; 063//检查是否有子栏目,并返回rel提示(用于二级菜单) 064if(ereg(':rel', $innertext)) $needRel = true; 065 066if(empty($sql)) return ''; 067$dsql->SetQuery($sql); 068$dsql->Execute(); 069 070$totalRow = $dsql->GetTotalRow(); 071$GLOBALS['autoindex'] = 0; 072for($i=0;$i < $line;$i++) 073{ 074if($col>1) $likeType .= "<dl>\r\n"; 075for($j=0;$j<$col;$j++) 076{ 077if($col>1) $likeType .= "<dd>\r\n"; 078if($row=$dsql->GetArray()) 079{ 080$row['sonids'] = $row['rel'] = ''; 081if($needRel) 082{ 083$row['sonids'] = GetSonIds($row['id'], 0, false); 084if($row['sonids']=='') $row['rel'] = ''; 085else $row['rel'] = " rel='dropmenu{$row['id']}'"; 086} 087//处理同级栏目中,当前栏目的样式 088if( ($row['id']==$typeid || ($topid==$row['id'] && $type=='top') ) && $currentstyle!='' ) 089{ 090if($currentstyle!='') 091{ 092$linkOkstr = $currentstyle; 093$row['typelink'] = GetOneTypeUrlA($row); 094$linkOkstr = str_replace("~rel~",$row['rel'],$linkOkstr); 095$linkOkstr = str_replace("~id~",$row['id'],$linkOkstr); 096$linkOkstr = str_replace("~typelink~",$row['typelink'],$linkOkstr); 097$linkOkstr = str_replace("~typename~",$row['typename'],$linkOkstr); 098$likeType .= $linkOkstr; 099} 100}else 101{ 102$row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row); 103if(is_array($dtp2->CTags)) 104{ 105foreach($dtp2->CTags as $tagid=>$ctag){ 106if(isset($row[$ctag->GetName()])) 107{ 108$dtp2->Assign($tagid,$row[$ctag->GetName()]); 109} 110elseif (preg_match('/^sonchannel[0-9]*$/',$ctag->GetName())) 111{ 112$dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql2)); 113} 114} 115} 116$likeType .= $dtp2->GetResult(); 117} 118} 119if($col>1) $likeType .= "</dd>\r\n"; 120$GLOBALS['autoindex']++; 121}//Loop Col 122if($col>1) 123{ 124$i += $col - 1; 125$likeType .= " </dl>\r\n"; 126} 127}//Loop for $i 128reset($dsql2); 129$dsql->FreeResult(); 130return $likeType; 131} 132function lib_channel_son($ctag,$typeid = 0,$dsql2) 133{ 134$attlist = "row|100,col|1,currentstyle|"; 135FillAttsDefault($ctag->CAttribute->Items,$attlist); 136extract($ctag->CAttribute->Items, EXTR_SKIP); 137$innertext = $ctag->GetInnerText(); 138$dsql3 = clone $dsql2; 139$likeType = ''; 140//if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid']; 141if($typeid==0) { 142return ''; 143} 144$sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description 145From dede_arctype where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row"; 146//And id<>'$typeid' 147$dtp2 = new DedeTagParse(); 148$dtp2->SetNameSpace("field","[","]"); 149$dtp2->LoadSource($innertext); 150$dsql2->SetQuery($sql); 151$dsql2->Execute(); 152$line = $row; 153for($i=0;$i < $line;$i++) 154{ 155if($col>1) $likeType .= "<dl>\r\n"; 156for($j=0;$j<$col;$j++) 157{ 158if($col>1) $likeType .= "<dd>\r\n"; 159if($row=$dsql2->GetArray()) 160{ 161$row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row); 162if(is_array($dtp2->CTags)) 163{ 164foreach($dtp2->CTags as $tagid=>$ctag){ 165if(isset($row[$ctag->GetName()])) 166{ 167$dtp2->Assign($tagid,$row[$ctag->GetName()]); 168} 169elseif (preg_match('/^sonchannel[0-9]*$/',$ctag->GetName())) 170{ 171$dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql3)); 172} 173} 174} 175$likeType .= $dtp2->GetResult(); 176} 177if($col>1) $likeType .= "</dd>\r\n"; 178}//Loop Col 179if($col>1) 180{ 181$i += $col - 1; 182$likeType .= " </dl>\r\n"; 183} 184}//Loop for $i 185reset($dsql3); 186$dsql2->FreeResult(); 187return $likeType; 188} 189?> |
2、在模板中调用实例:
01{dede:channel type='son' typeid='3'} 02[field:typename/] 03<ul> 04[field:sonchannel0] 05<li><a href="[field:typelink/]">[field:typename/]</a></li> 06[field:sonchannel1] 07<li><a href="[field:typelink/]">---[field:typename/]</a></li> 08[field:sonchannel2] 09<li><a href="[field:typelink/]">===[field:typename/]</a></li> 10[field:sonchannel3] 11<li><a href="[field:typelink/]">===[field:typename/]</a></li> 12[/field:sonchannel3] 13[/field:sonchannel2] 14[/field:sonchannel1] 15[/field:sonchannel0] 16</ul> 17{/dede:channel} |
下一篇:织梦Dedecms无法保存远程图片到本地服务器的解决方法
本文标题:织梦dede调用四级栏目内容的办法
本文地址:https://www.128sj.com/jiaocheng/201809131921.html,转载请注明出处