织梦DEDECMS扩展标签演示实例
我们可以看一个示例标签demotag.lib.php ,
if(!defed('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 = '';
返回这个值return $revalue;
$nertext = $ctag->GetInnerText();
$ctp = new DedeTagParse();
$ctp->SetNameSpace('field', '[', ']');
$sql = "SELECT FROM 58pic_archives WHERE writer='{$refObj->Fields['writer']}' limit 0, $row";
$dsql->Execute('me',$sql);
while($rs = $dsql->GetArray('me'))
{
$rs['title'] = _substr($rs['title'], $titlelen);
$ctp->LoadSource($nertext);
foreach($ctp->CTags as $tagid=>$ctag) {
if(!emptyempty($rs[strtolower($ctag->GetName())])) {
$ctp->Assign($tagid,$rs[$ctag->GetName()]);
}
}
$revalue .= $ctp->GetResult();
}
整个文件内容如下
if(!defed('DEDEINC'))
通过动态浏览页面进行查看调试?aid=3
{
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 = '';
$nertext = $ctag->GetInnerText();
$ctp = new DedeTagParse();
$ctp->SetNameSpace('field', '[', ']');
$sql = "SELECT FROM 58pic_archives WHERE writer='{$refObj->Fields['writer']}' limit 0, $row";
$dsql->Execute('me',$sql);
while($rs = $dsql->GetArray('me'))
{
$rs['title'] = _substr($rs['title'], $titlelen);
$ctp->LoadSource($nertext);
foreach($ctp->CTags as $tagid=>$ctag) {
if(!emptyempty($rs[strtolower($ctag->GetName())])) {
$ctp->Assign($tagid,$rs[$ctag->GetName()]);
}
}
$revalue .= $ctp->GetResult();
}
return $revalue;
}
?>
{dede:writerarc row='10' titlelen='6'}
[field:title/]
{/dede:writerarc}