zoukankan      html  css  js  c++  java
  • thinkphp3.2 实现上一篇和下一篇

    现在在做一个能够在内容页点击上一篇可以看到上一篇,点击下一篇可以看到下一篇.

    首先http://www.mmkb.com/zhendao/index/news_show?code=98

    现在code=98,显示的是"蝴蝶摘花来"这篇文章,那么点击下一页就是"这是我们想去的地方".

    前端

    <div class="head_bar">
            <span>位置:</span><a href="index.html">首页 </a> > <a href="news.html">新闻动态</a> > <span class="active">{$show.a_title}</span>
        </div>
        <div class="news_show">
            <span class="show_t">{$show.a_title}</span>
            <span class="fa_time">来源:珍岛   &nbsp;&nbsp;    发布时间:{$show.create_time|date='Y-m-d',###}</span>
            <p>
                {$show.a_remark}
            </p>
            <div class="s_img clearfix">
                <div class="pic">
                    <img src="__ROOT__/Public/Zhendao/images/show1.png" alt="" class="vcenter"/>
                    <i></i>
                </div>
                <div class="pic">
                    <img src="__ROOT__/Public/Zhendao/images/show2.png" alt="" class="vcenter"/>
                    <i></i>
                </div>    
            </div>
            <p>
                {$show.a_content}
            </p>
    
            <div class="s_x clearfix">
                <a href="{$furl}" class="s_prev">上一篇:{$ftitle}</a>      //上一篇
                <a href="{$aurl}" class="x_next">下一篇:{$atitle}</a>      //下一篇
            </div>
        </div>

    控制器

    public function news_show(){
            $code = $_GET['code'];
            $show = M("article")->where("a_id =$code")->find();
            $this->assign('show',$show);
            /*
             * 上一篇
             */
            $front=M("article")->where("a_id<$code and cate_id=56")->order('a_id desc')->limit('1')->find();      //找出小于当前页面的a_id,然后倒序找出第一个
            if($front){
                $furl='/zhendao/index/news_show?code='.$front['a_id'];      //拼接路径
                $ftitle = $front['a_title'];
            }else{
                $furl="javascript:void(0);";
                $ftitle = "没有了";                        //判断如果上一页没有文章,显示"没有了"
            }
            $this->assign('furl',$furl);
            $this->assign('ftitle',$ftitle);
            $this->assign('front',$front);
            /*
             * 下一篇
             */
            $after=M("article")->where("a_id>$code and cate_id=56 ")->order('a_id asc')->limit('1')->find();    //同理
            if($after){
                $aurl='/zhendao/index/news_show?code='.$after['a_id'];
                $atitle = $after['a_title'];
    
            }else{
                $aurl="javascript:void(0);";
                $atitle = "没有了";
            }
            $this->assign('aurl',$aurl);
            $this->assign('atitle',$atitle);
            $this->assign('after',$after);
    
    
            $this->display('/Public/news_show');
    
        }

    这样就完成了

  • 相关阅读:
    django之orm单表查询
    python通过os.system()方法执行pscp提示却找不到该应用程序
    VUE 条件编译
    博客园Silence新主题美化,2021年最新更新!换个口味~
    JavaScript中数组的操作方法总汇
    Vue 上传材料(使用input)
    postgresql关于array类型有交集(包含查询数据任意元素,有重叠&&)的一些查询方法以及sqlalchemy语句实现
    linux便捷日志查询操作
    安装RabbitMQ
    v-model语法糖在input上组件上的使用
  • 原文地址:https://www.cnblogs.com/shenzikun1314/p/7204403.html
Copyright © 2011-2022 走看看