thinkphp自定义模板标签(二)
上篇文章已经把自定义标签的准备工作讲完了;那么接下来就是见证...的时候了;没看如何配置的请先移步thinkphp自定义模板标签(一)
网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了丹东免费建站欢迎大家使用!
闭合标签就是单标签;比如a标签、img标签等等;
非闭合标签就是对标签;比如div、p标签等等;
这里以自定义的ueditor和recommend标签为例;
自定义的闭合标签比较适合用来引文件;
自定义的对标签比较适合调取数据库的数据并前台页面遍历显示;
array('attr'=>'name,content','close'=>0),
'recommend'=>array('attr'=>'limit','level'=>1)
);
/**
*引入ueidter编辑器
*@param string $tag name:表单name content:编辑器初始化后 默认内容
*/
public function _ueditor($tag){
$name=$tag['name'];
$content=$tag['content'];
$link=<<
$content
php;
return $link;
}
// 置顶推荐文章标签 cid为空时则抓取全部分类下的推荐文章
public function _recommend($tag,$content){
if(empty($tag['cid'])){
$where="is_show=1 and is_delete=0 and is_top=1";
}else{
$where='is_show=1 and is_delete=0 and is_top=1 and cid='.$tag['cid'];
}
$limit=$tag['limit'];
// p($recommend);
$php=<<field('aid,title')->where("$where")->limit($limit)->select();
foreach (\$recommend as \$k => \$field) {
\$url=U('Home/Index/article',array('aid'=>\$field['aid']));
?>
php;
$php.=$content; //拼字符串的过程。。。
$php.='';//foreach的回扩;
return $php;
}
}
?> 定义完成后在html页面中就可以直接使用
Document $field['aid']))}" target="_blank">{$k+1}:{$field['title']}
ueditor标签可以直接实例化ueditor编辑器
而如下图本站的热门推荐就是使用recommend遍历的;

当前名称:thinkphp自定义模板标签(二)
链接URL:http://www.jxjierui.cn/article/jodgjg.html


咨询
建站咨询
