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

黄舟
Release: 2023-03-14 19:32:02
Original
1822 people have browsed it

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);
Copy after login

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);
Copy after login

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>
Copy after login

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);
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!