读书人

ThinkPHP中获得下上篇文章的函数

发布时间: 2012-08-29 08:40:14 作者: rapoo

ThinkPHP中获得上下篇文章的函数

ThinkPHP中获得上下篇文章的函数,大家可以参考一下方法,稍微修改下就可以应用到其他网站上,方法一样!

//取得上下篇文章function PrevNext($id, $name = '', $where = array(), $fields = 'id,title'){$array = array();$model = M($name);$map = array();$map = $where;$map['id'] = array('lt',$id);$prevL = $model->field($fields)->where($map)->order('id desc')->find(); //上篇if(!$prevL){$prevL['id'] = '';$prevL['title'] = '暂无';}$map['id'] = array('gt',$id);$nextL = $model->field($fields)->where($map)->order('id asc')->find(); //下篇if(!$nextL){$nextL['id'] = '';$nextL['title'] = '暂无';}$array['prev'] = $prevL;$array['next'] = $nextL;return $array;}
?

读书人网 >PHP

热点推荐