百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>织梦CMS教程> dedecms在channel标签增加可选择范围的属性
分享文章到:

dedecms在channel标签增加可选择范围的属性

发布时间:12/03 来源: 浏览: 关键词:

changel的作用是调用网站栏目,根据row这个属性可以自定义调出栏目个数。但在有的频道页面需要调用一些指定ID几到几的一些栏目。可能有一些人想直接将链接写死在模版里。后来觉得这样对程序的扩展性不是很好。客户是不懂程序的,你不能指望他也会修改模版。于是就有了做这样一个小功能的想法。    

在原来的dede:channel基础上增加了一个limit属性。 limit是起点,row是条数

 

  1. {dede:channel type='son' limit='2' typeid='1' reid='1' row='10' "  
  2.  
  3. <a href='~typelink~' class='thisclass'>~typename~</a> |"}  
  4.  
  5.  <a href="[field:typelink/]"> 
  6.  
  7. <span class="aaa">[field:typename/]</span> 
  8.  
  9. </a>   
  10.  
  11. {/dede:channel}  

将以下的代码复制到--网站域名/include/taglib/channel.lib.php中进行覆盖:

  1. function lib_channel(&$ctag,&$refObj)  
  2. {  
  3.     global $dsql;  
  4.    
  5.     $attlist = "typeid|0,reid|0,row|100,col|1,type|son,currentstyle|,cacheid|,limit|0";  
  6.     FillAttsDefault($ctag->CAttribute->Items,$attlist);  
  7.     extract($ctag->CAttribute->Items, EXTR_SKIP);  
  8.     $innertext = $ctag->GetInnerText();  
  9.     $line = emptyempty($row) ? 100 : $row;  
  10.    
  11.     $likeType = '';  
  12.     //读取固定的缓存块  
  13.     $cacheid = trim($cacheid);  
  14.     if($cacheid !='') {  
  15.         $likeType = GetCacheBlock($cacheid);  
  16.         if($likeType != '') return $likeType;  
  17.     }  
  18.    
  19.     $reid = 0;  
  20.     $topid = 0;  
  21.     //如果属性里没指定栏目id,从引用类里获取栏目信息  
  22.     if(emptyempty($typeid))  
  23.     {  
  24.         if( isset($refObj->TypeLink->TypeInfos['id']) )  
  25.         {  
  26.             $typeid = $refObj->TypeLink->TypeInfos['id'];  
  27.             $reid = $refObj->TypeLink->TypeInfos['reid'];  
  28.             $topid = $refObj->TypeLink->TypeInfos['topid'];  
  29.         }  
  30.         else {  
  31.         $typeid = 0;  
  32.       }  
  33.     }  
  34.     //如果指定了栏目id,从数据库获取栏目信息  
  35.     else 
  36.     {  
  37.         $row2 = $dsql->GetOne("Select * From `dede_arctype` where id='$typeid' ");  
  38.         $typeid = $row2['id'];  
  39.         $reid = $row2['reid'];  
  40.         $topid = $row2['topid'];  
  41.         $issetInfos = true;  
  42.     }  
  43.    
  44.     if($type=='' || $type=='sun') $type='son';  
  45.     if($innertext=='') $innertext = GetSysTemplets("channel_list.htm");  
  46.    
  47.     if($type=='top')  
  48.     {  
  49.         $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath  
  50.           From `dede_arctype` where reid=0 And ishidden<>1 order by sortrank asc limit $limit, $line ";  
  51.     }  
  52.     else if($type=='son')  
  53.     {  
  54.         if($typeid==0) return '';  
  55.         $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath From `dede_arctype` where reid='$typeid' And ishidden<>1 order by sortrank asc limit $limit, $line ";  
  56.     }  
  57.     else if($type=='self')  
  58.     {  
  59.         if($reid==0) return '';  
  60.         $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath From `dede_arctype` where reid='$reid' And ishidden<>1 order by sortrank asc limit $limit, $line ";  
  61.     }  
  62.     //And id<>'$typeid'  
  63.     $needRel = false;  
  64.     $dtp2 = new DedeTagParse();  
  65.     $dtp2->SetNameSpace('field','[',']');  
  66.     $dtp2->LoadSource($innertext);  
  67.     //检查是否有子栏目,并返回rel提示(用于二级菜单)  
  68.     if(ereg(':rel', $innertext)) $needRel = true;  
  69.    
  70.     if(emptyempty($sql)) return '';  
  71.     $dsql->SetQuery($sql);  
  72.     $dsql->Execute();  
  73.    
  74.     $totalRow = $dsql->GetTotalRow();  
  75.     //如果用子栏目模式,当没有子栏目时显示同级栏目  
  76.     if($type=='son' && $reid!=0 && $totalRow==0)  
  77.     {  
  78.         $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath From `dede_arctype` where reid='$reid' And ishidden<>1 order by sortrank asc limit $limit, $line ";  
  79.         $dsql->SetQuery($sql);  
  80.       $dsql->Execute();  
  81.     }  
  82.     $GLOBALS['autoindex'] = 0;  
  83.     for($i=0;$i < $line;$i++)  
  84.     {  
  85.         if($col>1) $likeType .= "<dl>\r\n";  
  86.         for($j=0; $j<$col; $j++)  
  87.         {  
  88.             if($col>1) $likeType .= "<dd>\r\n";  
  89.             if($row=$dsql->GetArray())  
  90.             {  
  91.                 $row['sonids'] = $row['rel'] = '';  
  92.                 if($needRel)  
  93.                 {  
  94.                     $row['sonids'] = GetSonIds($row['id'], 0, false);  
  95.                     if($row['sonids']=='') $row['rel'] = '';  
  96.                     else $row['rel'] = " rel='dropmenu{$row['id']}'";  
  97.                 }  
  98.                 //处理同级栏目中,当前栏目的样式  
  99.                 if( ($row['id']==$typeid || ($topid==$row['id'] && $type=='top') ) && $currentstyle!='' )  
  100.                 {  
  101.                     $linkOkstr = $currentstyle;  
  102.                     $row['typelink'] = GetOneTypeUrlA($row);  
  103.                     $linkOkstr = str_replace("~rel~",$row['rel'],$linkOkstr);  
  104.                     $linkOkstr = str_replace("~id~",$row['id'],$linkOkstr);  
  105.                     $linkOkstr = str_replace("~typelink~",$row['typelink'],$linkOkstr);  
  106.                     $linkOkstr = str_replace("~typename~",$row['typename'],$linkOkstr);  
  107.                     $likeType .= $linkOkstr;  
  108.                 }  
  109.                 else 
  110.                 {  
  111.                     $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);  
  112.                     if(is_array($dtp2->CTags))  
  113.                     {  
  114.                         foreach($dtp2->CTags as $tagid=>$ctag)  
  115.                         {  
  116.                             if(isset($row[$ctag->GetName()])) $dtp2->Assign($tagid,$row[$ctag->GetName()]);  
  117.                         }  
  118.                     }  
  119.                     $likeType .= $dtp2->GetResult();  
  120.                 }  
  121.             }  
  122.             if($col>1) $likeType .= "</dd>\r\n";  
  123.             $GLOBALS['autoindex']++;  
  124.         }  
  125.         //Loop Col  
  126.         if($col>1)  
  127.         {  
  128.             $i += $col - 1;  
  129.             $likeType .= "  </dl>\r\n";  
  130.         }  
  131.     }  
  132.     //Loop for $i  
  133.     $dsql->FreeResult();  
  134.     if($cacheid !='') {  
  135.         WriteCacheBlock($cacheid, $likeType);  
  136.     }  
  137.     return $likeType;  
打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有9人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板