一个资源分享、信息整合的综合性站点。

标题: 织梦用sonchannel标签做一个三级菜单 [打印本页]

作者: 树苗收集系    时间: 2020-12-27 15:00
标题: 织梦用sonchannel标签做一个三级菜单
一、修改文件:\include\taglib目录下的channel.lib.php
复制以下内容覆盖旧文件。  
  1.   
  2.   一、修改文件:\include\taglib目录下的channel.lib.php
  3.   <?php
  4.   functionlib_channel(&$ctag,&$refObj)
  5.   {
  6.   global$_sys_globals,$envs,$dsql;
  7.   $attlist="typeid|0,reid|0,row|100,col|1,type|son,currentstyle|";
  8.   FillAttsDefault($ctag->CAttribute->Items,$attlist);
  9.   extract($ctag->CAttribute->Items,EXTR_SKIP);
  10.   $innertext=$ctag->GetInnerText();
  11.   $cacheid=trim($cacheid);
  12.   if($cacheid!=''){
  13.   $likeType=GetCacheBlock($cacheid);
  14.   if($likeType!='')return$likeType;
  15.   }
  16.   $reid=0;
  17.   $topid=0;
  18.   if(empty($typeid)&&$envs['typeid']!=0)
  19.   {
  20.   $typeid=$envs['typeid'];
  21.   $reid=$envs['reid'];
  22.   }else{
  23.   $reid=0;
  24.   }
  25.   if($type==''||$type=='sun')$type="son";
  26.   if($innertext=='')$innertext=GetSysTemplets("channel_list.htm");
  27.   if($reid==0&&$typeid>0)
  28.   {
  29.   $dbrow=$dsql->GetOne("SelectreidFromdede_arctypewhereid='$typeid'");
  30.   if(is_array($dbrow))$reid=$dbrow['reid'];
  31.   }
  32.   $likeType='';
  33.   if($type=='top')
  34.   {
  35.   $sql="Selectid,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  36.   Fromdede_arctypewherereid=0Andishidden<>1orderbysortrankasclimit0,$row";
  37.   }
  38.   elseif($type=="son")
  39.   {
  40.   //if($_sys_globals['typeid']>0)$typeid=$_sys_globals['typeid'];
  41.   if($typeid==0){
  42.   return'';
  43.   }
  44.   $sql="Selectid,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  45.   Fromdede_arctypewherereid='$typeid'Andishidden<>1orderbysortrankasclimit0,$row";
  46.   }
  47.   elseif($type=="self")
  48.   {
  49.   if($reid==0){
  50.   return'';
  51.   }
  52.   $sql="Selectid,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  53.   From`dede_arctype`wherereid='$reid'Andishidden<>1orderbysortrankasclimit0,$row";
  54.   }
  55.   //Andid<>'$typeid'
  56.   $needRel=false;
  57.   $dtp2=newDedeTagParse();
  58.   $dtp2->SetNameSpace("field","[","]");
  59.   $dtp2->LoadSource($innertext);
  60.   $dsql2=clone$dsql;
  61.   $dsql->SetQuery($sql);
  62.   $dsql->Execute();
  63.   $line=$row;
  64.   //检查是否有子栏目,并返回rel提示(用于二级菜单)
  65.   if(ereg(':rel',$innertext))$needRel=true;
  66.   if(empty($sql))return'';
  67.   $dsql->SetQuery($sql);
  68.   $dsql->Execute();
  69.   $totalRow=$dsql->GetTotalRow();
  70.   $GLOBALS['autoindex']=0;
  71.   for($i=0;$i<$line;$i++)
  72.   {
  73.   if($col>1)$likeType.="<dl>\r\n";
  74.   for($j=0;$j<$col;$j++)
  75.   {
  76.   if($col>1)$likeType.="<dd>\r\n";
  77.   if($row=$dsql->GetArray())
  78.   {
  79.   $row['sonids']=$row['rel']='';
  80.   if($needRel)
  81.   {
  82.   $row['sonids']=GetSonIds($row['id'],0,false);
  83.   if($row['sonids']=='')$row['rel']='';
  84.   else$row['rel']="rel='dropmenu{$row['id']}'";
  85.   }
  86.   //处理同级栏目中,当前栏目的样式
  87.   if(($row['id']==$typeid||($topid==$row['id']&&$type=='top'))&&$currentstyle!='')
  88.   {
  89.   if($currentstyle!='')
  90.   {
  91.   $linkOkstr=$currentstyle;
  92.   $row['typelink']=GetOneTypeUrlA($row);
  93.   $linkOkstr=str_replace("~rel~",$row['rel'],$linkOkstr);
  94.   $linkOkstr=str_replace("~id~",$row['id'],$linkOkstr);
  95.   $linkOkstr=str_replace("~typelink~",$row['typelink'],$linkOkstr);
  96.   $linkOkstr=str_replace("~typename~",$row['typename'],$linkOkstr);
  97.   $likeType.=$linkOkstr;
  98.   }
  99.   }else
  100.   {
  101.   $row['typelink']=$row['typeurl']=GetOneTypeUrlA($row);
  102.   if(is_array($dtp2->CTags))
  103.   {
  104.   foreach($dtp2->CTagsas$tagid=>$ctag){
  105.   if(isset($row[$ctag->GetName()]))
  106.   {
  107.   $dtp2->Assign($tagid,$row[$ctag->GetName()]);
  108.   }
  109.   elseif(preg_match('/^sonchannel[0-9]*$/',$ctag->GetName()))
  110.   {
  111.   $dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql2));
  112.   }
  113.   }
  114.   }
  115.   $likeType.=$dtp2->GetResult();
  116.   }
  117.   }
  118.   if($col>1)$likeType.="</dd>\r\n";
  119.   $GLOBALS['autoindex']++;
  120.   }//LoopCol
  121.   if($col>1)
  122.   {
  123.   $i+=$col-1;
  124.   $likeType.="</dl>\r\n";
  125.   }
  126.   }//Loopfor$i
  127.   reset($dsql2);
  128.   $dsql->FreeResult();
  129.   return$likeType;
  130.   }
  131.   functionlib_channel_son($ctag,$typeid=0,$dsql2)
  132.   {
  133.   $attlist="row|100,col|1,currentstyle|";
  134.   FillAttsDefault($ctag->CAttribute->Items,$attlist);
  135.   extract($ctag->CAttribute->Items,EXTR_SKIP);
  136.   $innertext=$ctag->GetInnerText();
  137.   $dsql3=clone$dsql2;
  138.   $likeType='';
  139.   //if($_sys_globals['typeid']>0)$typeid=$_sys_globals['typeid'];
  140.   if($typeid==0){
  141.   return'';
  142.   }
  143.   $sql="Selectid,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  144.   Fromdede_arctypewherereid='$typeid'Andishidden<>1orderbysortrankasclimit0,$row";
  145.   //Andid<>'$typeid'
  146.   $dtp2=newDedeTagParse();
  147.   $dtp2->SetNameSpace("field","[","]");
  148.   $dtp2->LoadSource($innertext);
  149.   $dsql2->SetQuery($sql);
  150.   $dsql2->Execute();
  151.   $line=$row;
  152.   for($i=0;$i<$line;$i++)
  153.   {
  154.   if($col>1)$likeType.="<dl>\r\n";
  155.   for($j=0;$j<$col;$j++)
  156.   {
  157.   if($col>1)$likeType.="<dd>\r\n";
  158.   if($row=$dsql2->GetArray())
  159.   {
  160.   $row['typelink']=$row['typeurl']=GetOneTypeUrlA($row);
  161.   if(is_array($dtp2->CTags))
  162.   {
  163.   foreach($dtp2->CTagsas$tagid=>$ctag){
  164.   if(isset($row[$ctag->GetName()]))
  165.   {
  166.   $dtp2->Assign($tagid,$row[$ctag->GetName()]);
  167.   }
  168.   elseif(preg_match('/^sonchannel[0-9]*$/',$ctag->GetName()))
  169.   {
  170.   $dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql3));
  171.   }
  172.   }
  173.   }
  174.   $likeType.=$dtp2->GetResult();
  175.   }
  176.   if($col>1)$likeType.="</dd>\r\n";
  177.   }//LoopCol
  178.   if($col>1)
  179.   {
  180.   $i+=$col-1;
  181.   $likeType.="</dl>\r\n";
  182.   }
  183.   }//Loopfor$i
  184.   reset($dsql3);
  185.   $dsql2->FreeResult();
  186.   return$likeType;
  187.   }
  188.   ?>
  189.   
复制代码




二:巧用sonchannel标签做三级菜单  
{dede:channelartlisttypeid='72'}  
{/dede:channelartlist}//调用顶级栏目(一级菜单)  
dede:channeltype='son'}  
{/dede:channel}//二级菜单  
[field:sonchannel0]//无限获取三级菜单  

实例:  
  1. divclass="nav">
  2. <divclass="nav-l">
  3. <ahref=http://www.002y.com/dedecmsjc/"/"><spanclass="nav-l-span">顶级菜单<i></i></span></a>
  4. <divclass="nav-submenu">
  5. <divid="submenu">
  6. {dede:channelartlisttypeid='72'}
  7. <divclass="submenu1">
复制代码



作者: 撒哈拉的泪    时间: 2020-12-29 15:44
谢谢楼主,,,收藏ing
作者: 天使爱上吸血鬼    时间: 2021-1-8 16:24
谢谢楼主,,,收藏ing
作者: 淡看红尘轻笑孤    时间: 2021-3-14 14:58
这个好好支持一下




欢迎光临 一个资源分享、信息整合的综合性站点。 (https://sorv.cn/) Powered by Discuz! X3.4