Home  >  Article  >  Backend Development  >  Example analysis of how to implement the previous and next articles in Thinkphp

Example analysis of how to implement the previous and next articles in Thinkphp

黄舟
黄舟Original
2017-08-09 10:13:001872browse

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(&#39;id<"&#39;.$_GET["news"].&#39;"&#39;)->order(&#39;id desc&#39;)->limit(&#39;1&#39;)->select();
$this->assign(&#39;next&#39;,$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?&#39;没有了&#39;:&#39;.__URL__.&#39;/cm/&#39;.$pre[&#39;nid&#39;].&#39;"<&#39;.$pre[&#39;title&#39;].&#39;&#39;; 
$this->assign(&#39;pre&#39;,$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!

Statement:
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