给dedecms增加自定义标签方法
如果有读者对方法的参数&$ctag,&$refobj不是很清楚,请从index.php教程中的处理开始查看,具体的应该是在include目录下的dedetag.class.php中。
下面,我们仿照上面的例子自己去写一个标签
<?php if (! defined ( 'dedeinc' )) { exit ( "request error!" ); } function lib_aaa(&$ctag, &$refobj) { global $dsql; $attlist = "topid|0,row|10"; fillattsdefault ( $ctag->cattribute->items, $attlist ); extract ( $ctag->cattribute->items, extr_skip ); $condtion=""; $revalue=''; if($topid==0) { $condtion.=" where topid=0"; } elseif ($topid!=0) { $condtion.=" where topid <> 0"; } $equery="select * from `#@__arctype` $condtion"; if(trim($ctag->getinnertext())=='') $innertext = "<li>[field:typename /]</li>"; else $innertext = $ctag->getinnertext(); $dsql->setquery($equery); $dsql->execute(); while($dbrows=$dsql->getobject()) { $rbtext = preg_replace("/[field:typename([/s]{0,})]/isu",$dbrows->typename, $innertext); $revalue.=$rbtext; } return $revalue; }
上面的代码比较简单,在这里就不做解释了,直接看测试结果:
//这个测试不包含innertext,默认输出应该是<li><br>{dede:aaa topid='0'row=10} {/dede:aaa}
//自带的innertext,应该输出是按照加粗+分割线格式
{dede:aaa topid='0'row=10} <b>[field:typename /]</b><hr /> {/dede:aaa}
大家测试一下全输出什么结果呢。
本文地址:http://www.phprm.com/frame/38015.html
转载随意,但请附上文章地址:-)