搜索
系统检测到您的用户名不符合规范:

自己弄得一个简单的标签扩展,可以参考下

浏览:706 发布日期:2015年07月20日 分类:技术分享
提供类似的方法,大家自已扩展,我也是找了很多资料才弄出来,费了老大劲<?php
/**
* Created by PhpStorm.
* User: zhibo
* 15-7-14 下午10:56
* Mail:ni5400@163.com
* Web:http://www.ki35.com
*/
namespace Think\Template\TagLib;
use MyLibrary\Category;
use Think\Template\TagLib;
//自定义栏目标签库
class Ki35 extends TagLib{
// 标签定义
protected $tags = array(
//close 1是闭合标签,0是短标签 attr是定义包含的属性
'category' =>array('attr'=>'limit,order','close'=>1),
'nature' =>array('attr'=>'limit,order,nature_id,status,','close'=>1),
'list' =>array('attr'=>'limit,order','close'=>1),
'prev' =>array('attr'=>'limit,order','close'=>1),
'next' =>array('attr'=>'limit,order','close'=>1),
);
//查询导航,及二级导航
public function _category($tag,$content){
$limit = $tag['limit'];
$order = $tag['order'];
$str='<?php ';
$str.='$cateList=M("Category")->select();';
$str.='$Category=new MyLibrary\Category();';
$str.='$cateList=$Category->cate_ullist($cateList);';
$str.='foreach($cateList as $cateList_v) :';
$str.='extract($cateList_v);';
$str.='$url=U("/"."Blog/category_".$id)';
$str.='?>';
$str.=$content;
$str.='<?php endforeach;?>';
return $str;
}

//查询某推荐位下的多条信息
public function _nature($tag,$content){
$naturelimit = $tag['limit'];
$natureorder = $tag['order'];
$nature_id =$tag['nature_id'];
$status =$tag['status'];
$str='<?php ';
$str.='$natruemap["nature_id"]='.$nature_id.';';
$str.='$natruemap["status"]='.$status.';';
$str.='$natureList=D("NatureView")->where($natruemap)->limit("'.$naturelimit.'")->order("'.$natureorder.'")->select();';
$str.='foreach($natureList as $natureList_v) :';
$str.='extract($natureList_v);';
$str.='$url=U("/"."Blog/notes/".$id)';
$str.='?>';
$str.=$content;
$str.='<?php endforeach;?>';
return $str;
}

//获取当前栏目的list列表,如果当前栏目不存在则获取所有栏目
public function _list($tag,$content){
$limit = $tag['limit'];
$order = $tag['order'];
$str='<?php ';
$str.='if(I("cate_id","","intval")) $thisMap["catid"]=array("eq",I("cate_id","intval"));';
$str.='$aList=M("Article")->field("id,title,hits,add_time,update_time")->where($thisMap)->limit("'.$limit.'")->order("'.$order.'")->select();';
$str.='foreach($aList as $aList_v) :';
$str.='extract($aList_v);';
$str.='$url=U("/"."Blog/notes/".$id)';
$str.='?>';
$str.=$content;
$str.='<?php endforeach;?>';
return $str;
}

//获取上一/几条数据
public function _prev($tag,$content){
$limit = $tag['limit'];
$str='<?php ';
$str.='if(I("id","","intval")) $thisMap["id"]=array("lt",I("id","intval"));';
$str.='$prevList=M("Article")->field("id,title")->where($thisMap)->limit("'.$limit.'")->order("id Desc")->select();';
$str.='foreach($prevList as $prevList_v) :';
$str.='extract($prevList_v);';
$str.='$url=U("/"."Blog/notes/".$id)';
$str.='?>';
$str.=$content;
$str.='<?php endforeach;?>';
return $str;
}
//获取下一/几条数据
public function _next($tag,$content){
$limit = $tag['limit'];
$str='<?php ';
$str.='if(I("id","","intval")) $thisMap["id"]=array("gt",I("id","intval"));';
$str.='$nextList=M("Article")->field("id,title")->where($thisMap)->limit("'.$limit.'")->select();';
$str.='foreach($nextList as $nextList_v) :';
$str.='extract($nextList_v);';
$str.='$url=U("/"."Blog/notes/".$id)';
$str.='?>';
$str.=$content;
$str.='<?php endforeach;?>';
return $str;
}

}
使用案例:<{ki35:nature order="update_time DESC" nature_id="5" limit="5" status="1"}>
<li class="clearfix">
<div class="blog-new-article-list-img"><a href="<{$url}>"><img src="<{if condition='$thumb'}><{$thumb}><{else /}>/Public/Blog/images/550d30755870c.png<{/if}>" alt="<{$title}>" width="96" height="54"></a></div>
<div class="blog-new-atticle-list-digest">
<h3><a href="<{$url}>"><{$title}></a></h3>
<p><{$introduce}></p>
</div>
</li>
<{/ki35:nature}>
最佳答案
评论() 相关
后面还有条评论,
评论支持使用[code][/code]标签添加代码
您需要登录后才可以评论 登录 | 立即注册
收藏
ni5400
积分:989 等级:LV2
热点推荐
(追記) (追記ここまで)
最新更新

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /