dedecms 自定义标签的方法

it2025-04-11  8

function lib_demotest(&$ctag,&$refObj) { global $dsql,$envs; //属性处理 $attlist="row|12,titlelen|24"; FillAttsDefault($ctag->CAttribute->Items,$attlist); extract($ctag->CAttribute->Items, EXTR_SKIP); $revalue = ''; $innertext = $ctag->GetInnerText(); $ctp = new DedeTagParse(); $ctp->SetNameSpace('field', '[', ']'); $sql = "SELECT * FROM dede_archives WHERE 1=1 limit 0, $row"; $dsql->Execute('me',$sql); while($rs = $dsql->GetArray('me')) { //根据属性处理查询变量 $rs['title'] = cn_substr($rs['title'], $titlelen); //获取底层模板 $ctp->LoadSource($innertext); foreach($ctp->CTags as $tagid=>$ctag) { if(!empty($rs[strtolower($ctag->GetName())])) { $ctp->Assign($tagid,$rs[$ctag->GetName()]); } } //根据底层模板及查询变量得到处理结果 $revalue .= $ctp->GetResult(); } return $revalue; }

 在include/taglib/建一个demotest.lib.php  文件

 

然在需要的模板文件里加入

{dede:demotest row='10' titlelen='36'}   [field:title/]   {/dede:demotest}

 

转载于:https://www.cnblogs.com/vania/p/4522500.html

相关资源:DEDECMS 扩展标签和dede自定义标签实现方法
最新回复(0)