当前位置: 代码迷 >> PHP >> ThinkPHP中获得下上篇文章的函数
  详细解决方案

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

热度:82   发布时间:2016-04-29 00:07:58.0
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;}
?