TP3.2 realizes switching between previous and next chapters

一个新手
Release: 2023-03-15 22:58:01
Original
1586 people have browsed it

To implement the previous article and the next article, a primary key value needs to be passed. Let’s take news as an example. The first is the news list. When I click on the list, I will enter the content page, so when I click on the news list:

Front-end page:


<span>{$v.a_content}</span><a href="{$v.a_writer}?id={$v.a_id}">阅读详细</a></p></p></section>
Copy after login

In this way, you can get the primary key; then enter the content page

The content page has the previous article and Next article;

Controller:


<? 
 //新闻内
    public function index04(){        
        $this->ff();        
        $idds = I(&#39;get.id&#39;);             
            //上一篇
        $shang = M(&#39;article&#39;)->where("a_id <$idds and a_keyword=489")->order(&#39;a_id desc&#39;)->limit(&#39;1&#39;)->find();//查数据
            if($shang){//              判断如果执行成功往前面扔
        $this->assign(&#39;shang&#39;,$shang);

       }       
       else{//         否则让他的标题等于暂无吧
            $shang[&#39;a_title&#39;] = "暂无";            
            $this->assign(&#39;shang&#39;,$shang);
        }        
//      下一篇
//同上
             $xia = M(&#39;article&#39;)->where("a_id >$idds and a_keyword=489")->order(&#39;a_id asc&#39;)->limit(&#39;1&#39;)->find();         
         if($xia){        
             $this->assign(&#39;xia&#39;,$xia);

       }       
       else{            
           $xia[&#39;a_title&#39;] = "暂无";            
           $this->assign(&#39;xia&#39;,$xia);
        }        
        
           $this->display(&#39;jiu:public/7-6newsview&#39;);
     }
Copy after login

Front end:


##

  <span class="prev">上一篇:<A href="{$shang.a_writer}?id={$shang.a_id}">{$shang.a_title}</A></span>
           <span class="next">下一篇:<A href="{$xia.a_writer}?id={$xia.a_id}">{$xia.a_title}</A></span>
Copy after login

The above is the detailed content of TP3.2 realizes switching between previous and next chapters. 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