织梦DEDECMS扩展标签怎么用
2020-01-11 16:52织梦CMS
织梦DEDECMS扩展标签怎么用?
织梦DEDECMS扩展标签演示实例
我们可以看一个示例标签:demotag.lib.php ,
if(!defined('DEDEINC')) { exit("Request Error!"); } function lib_demotag(&$ctag,&$refObj) { global $dsql,$envs; $attlist="row|12,titlelen|24"; FillAttsDefault($ctag->CAttribute->Items,$attlist); extract($ctag->CAttribute->Items, EXTR_SKIP); $revalue = ''; //------------------------------------------------------ $revalue = 'Hello Word!'; //------------------------------------------------------ return $revalue; } ?>
我们会发现标签起作用了,输出了我们的内容。
$revalue = 'Hello Word!'; $revalue .=" Row:".$row.";TitleLen:".$titlelen;
这样我们可以看到,这个属性已经被创建变量并且赋值了。
接下来我们可以再进一步去修改这个标签。
function lib_writerarc(&$ctag,&$refObj)
接下来我们就可以编写查询语句及对底层模板处理的相关函数了
$revalue = ''; $innertext = $ctag->GetInnerText(); $ctp = new DedeTagParse(); $ctp->SetNameSpace('field', '[', ']'); $sql = "SELECT * FROM dede_archives WHERE writer='{$refObj->Fields['writer']}' 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(!emptyempty($rs[strtolower($ctag->GetName())])) { $ctp->Assign($tagid,$rs[$ctag->GetName()]); } } $revalue .= $ctp->GetResult(); }
最后返回这个值return $revalue;
整个文件内容如下:
if(!defined('DEDEINC')) { exit("Request Error!"); } function lib_writerarc(&$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 writer='{$refObj->Fields['writer']}' 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(!emptyempty($rs[strtolower($ctag->GetName())])) { $ctp->Assign($tagid,$rs[$ctag->GetName()]); } } $revalue .= $ctp->GetResult(); } return $revalue; } ?>
通过动态浏览页面进行查看调试?aid=3
{dede:writerarc row='10' titlelen='6'} [field:title/] {/dede:writerarc}
以上就是织梦DEDECMS扩展标签怎么用的详细内容,更多请关注下载帮php中文频道其它相关文章!
很赞哦! ()