Home > Backend Development > PHP Tutorial > ThinkPHP中获得下上篇文章的函数

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

WBOY
Release: 2016-06-13 10:40:55
Original
899 people have browsed it

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;}
Copy after login
?
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template