当前位置:首页 > CMS教程 > DeDecms > 列表

dedecms 添加自定义标签方法

发布:smiling 来源: PHP粉丝网  添加日期:2015-03-28 17:06:19 浏览: 评论:0 

dedecms 添加自定义标签方法,include/taglib/hongyungoods.lib.php:

  1. <?php 
  2. /** 
  3.  * @author http://www.phpfensi.com/  
  4.  */ 
  5. if(!defined('dedeinc')) exit('request error!'); 
  6.  
  7. functionlib_hongyungoods(&$ctag, &$refobj) 
  8. { 
  9.     global$dsql, $envs, $cfg_cmsurl; 
  10.  
  11.     //属性处理 
  12.     $attlist="row|6,titlelen|0,tid|0"; 
  13.     fillattsdefault($ctag->cattribute->items,$attlist); 
  14.     extract($ctag->cattribute->items, extr_skip); 
  15.  
  16.     //只在指定栏目显示 
  17.     if($tid>0 && $tid!= $envs['typeid']) return''; 
  18.  
  19.     if( !$dsql->istable("sl_products") ) return'没安装鸿运产品模块'; 
  20.  
  21.     $innertext= $ctag->getinnertext(); 
  22.     //@todo hongyungoods.htm 
  23.     if(trim($innertext)=='') $innertext= getsystemplets("hongyungoods.htm"); 
  24.  
  25.     //@todo 智能条件 
  26.     $where= 1; 
  27.     $limit= 5; 
  28.  
  29.     $ctp= newdedetagparse(); 
  30.     $ctp->setnamespace('field', '[', ']'); 
  31.     $ret= ''; 
  32.     $query= "select p.`name` as title, 
  33.  concat('http://www.hongyun2000.com/', ps.`acstr`, '-view-', p.`id`, '.html') as url, 
  34.  concat('http://www.hongyun2000.com/uploadfile/s/', p.`images`) as img 
  35.  from `sl_products` as p 
  36.  left join `sl_products_sort` as ps on p.`sid` = ps.`id` 
  37.  where " . $where . "order by rand() limit " . $limit; 
  38.  
  39.     $dsql->execute('me',$query); 
  40.   while($rs= $dsql->getarray('me')) 
  41.   { 
  42.       $rs['title'] = 0 == $titlelen?$rs['title']:cn_substr($rs['title'], $titlelen); 
  43.         $ctp->loadsource($innertext); 
  44.       foreach($ctp->ctags as$tagid=>$ctag) { 
  45.             if(!emptyempty($rs[strtolower($ctag->getname())])) { 
  46.                 $ctp->assign($tagid,$rs[$ctag->getname()]); 
  47.             } 
  48.           } 
  49.           $ret.= $ctp->getresult(); 
  50.   } 
  51.  
  52.   return$ret; 
  53. } 
  54.  
  55. ?> 

调用页面使用:

  1. {dede:hongyungoods} 
  2. <dd> 
  3.     <spanclass="tlink"><ahref="[field:url/]"><imgsrc="[field:img/]"alt="[field:title/]"/></a> 
  4.     <ahref="[field:url/]"target="_blank">[field:title/]</a></span> 
  5. </dd> 
  6. {/dede:hongyungoods}

Tags: dedecms标签 dedecms自定义

分享到: