标签:
我们用大I接收到我们get过来的栏目页的id然后通过文章的ar_cateid 来判断是不是属于该栏目下的,如果文章表ar_cateid = 栏目表的cate_id 那么就可以选出我们要查找的信息,
然后再遍历到视图即可。。。
<?php namespace Home\Controller; use Think\Controller; class ListsController extends CommonController { public function lists(){ //获取栏目的id $catid = I(‘cate_id‘); $mod = M(‘Article‘); $totalRows = $mod->table("jj_category cate,jj_article art")-> where("cate.cate_id=art.ar_cateid and art.ar_cateid=$catid")-> field(‘cate.cate_name,art.*‘)-> count(); //创建分页对象时,分页对象需要总记录数和分页条数 $page = new \Think\Page($totalRows,2); $page -> rollPage =5; //分页列表上显示多少条 $page->setConfig(‘theme‘,‘%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%‘); $page->setConfig(‘first‘,‘首页‘); $page->setConfig(‘prev‘,‘上一页‘); $page->setConfig(‘next‘,‘下一页‘); $page->setConfig(‘last‘,‘尾页‘); $pageHtml = $page -> show();//生成分页的连接诶效果(分页工具条的html代码) $this -> assign(‘pageHtml‘,$pageHtml);//分配分页栏到模版 //2.查询出当前页面的列表数据 $amod = $mod -> table("jj_category cate,jj_article art")-> where("cate.cate_id=art.ar_cateid and art.ar_cateid=$catid")-> field(‘cate.cate_name,art.*‘)-> page(I(‘get.p‘,1),$page->listRows)->select(); $this -> assign(‘amod‘,$amod); //dump($amod); $this->display(); } }
然后开始将列表页的的数据在模版中遍历出来即可:
<!doctype html> <html> <head> <base target="_self" /> <meta charset="UTF-8"> <title>创宜生物</title> <link type="text/css" rel="stylesheet" href="__PUBLIC__/Home/style/style.css" /> <script type="text/javascript" src="__PUBLIC__/Home/style/jquery-1.8.0.min.js"></script> </head> <body> <include file="Public/header" /> <div id="full-screen-slider-sec"> <div class="layout"> <div class="page-title"> {$catetop[‘cate_name‘]} </div> </div> </div> <div class="main"> <div class="layout cnt2"> <div class="left"> <ul> <li><a href="/plus/list.php?tid=8" class="foucs">公司新闻</a></li> <li><a href="/plus/list.php?tid=9" class="1">国际交流</a></li> <li><a href="/plus/list.php?tid=10" class="2">行业资讯</a></li> </ul> </div> <div class="right"> <h1> <div class="page"> <a href=‘__APP__‘>网站首页</a> > <volist name="res" id="vo"> <if condition="$vo[‘cate_type‘] eq ‘0‘" > <a href=‘__MODULE__/page/page/cate_id/{$vo[‘cate_id‘]}‘>{$vo[‘cate_name‘]}</a> <elseif condition="$vo[‘cate_type‘] eq ‘1‘" /> <a href=‘__MODULE__/lists/lists/cate_id/{$vo[‘cate_id‘]}‘>{$vo[‘cate_name‘]}</a> </if> <if condition="$i neq count($res)"> > </if> </volist> </div> {$cateone[‘cate_name‘]} </h1> <div class="cnt-in"> <div class="news-list-wimg"> <ul> <volist name="amod" id="vo"> <li> <h3> <a href="/news/company/2016/0324/35.html">{$vo[‘ar_title‘]}</a> </h3> <div style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width:868px; height:122px;"> <if condition="$vo[‘ar_pic‘] eq ‘‘ "> <img src="__PUBLIC__/Home/not.jpg" width="120" height="90" style="float:left; margin-right:15px;"> <else /> <img src="/{$vo[‘ar_pic‘]}" width="120" height="90" style="float:left; margin-right:15px;"> </if> {$vo[‘ar_content‘]|htmlspecialchars_decode|substr=0,300} <span class="list-date"> {$vo[‘ar_time‘]|date="Y-m-d H:i:s",###} </span> </div> </li> </volist> </ul> </div> <div class="pages"> {$pageHtml} </div> </div> </div> <div class="clr"></div> </div> </div> <include file="Public/footer" /> </body> </html>
最终效果如下所示:
夺命雷公狗ThinkPHP项目之----企业网站26之网站前台列表页的显示和完成分页功能
标签:
原文地址:http://www.cnblogs.com/leigood/p/5437385.html