Home > Article > Backend Development > Example analysis of how to implement the previous and next articles in Thinkphp
Share a method to implement the previous and next articles in the thinkphp framework. It is more practical and can solve the problem of discontinuous IDs.
Implement the previous article
$pre=$m->where('id>"'.$_GET["news"].'"')->limit('1')->select(); $this->assign('pre',$pre);
Implement the next article
$next=$m->where('id<"'.$_GET["news"].'"')->order('id desc')->limit('1')->select(); $this->assign('next',$next);
Calling data
<p class="pre_next"> <volist name="pre" id="pre"> <p>上一篇:<a href="http://www...com/Index/newslist?news=<{$pre.id}>&&n=News"><{$pre.title}></a></p> </volist> <volist name="front" id="front"> <p>下一篇:<a href="http://www...com/Index/newslist?news=<{$next.id}>&&n=News"><{$next.title}></a></p> </volist> </p>
Implementation of judgment function
$p=!$pre?'没有了':'.__URL__.'/cm/'.$pre['nid'].'"<'.$pre['title'].''; $this->assign('pre',$p);
The above is the detailed content of Example analysis of how to implement the previous and next articles in Thinkphp. For more information, please follow other related articles on the PHP Chinese website!