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; }?