织梦dede调用四级栏目内容的办法-免费资源网
1G全能免费空间 | 2GB免费全能空间 | 1G免费全能空间 | 免费试用云服务器 | 国内1G免费空间 | 免费空间 | 免费空间申请
您的位置:首页 > 免费教程

织梦dede调用四级栏目内容的办法

作者:免费空间 发布时间:2018-09-13 09:12:09 [手机版]

织梦调用四级子栏目,首先需要修改文件:\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}


相关推荐
免费空间声明:
(一) 由于各方面情况的调整与变化,本网所提供的考试信息仅供参考,敬请以权威部门公布的正式信息为准。
(二) 本网注明来源为其他媒体的稿件均为转载稿,免费转载出于非商业性学习目的,版权归原作者所有。如有内容、版权等问题请在30日内与本网联系。联系方式:邮件 jiansou123@126.com
最近更新
网站地图 | XML地图 | 手机版
版权所有 © 2005-2022 www.128sj.com 免费空间 All Rights Reserved
本网站所有信息全是来源于互联网,如有侵权请来电咨询! 粤ICP备16040413号-1