thinkCMF----列表页跳转

thinkCMF列表循环有个:用来循环文章列表。

<php>
    $where=[
    'post.create_time'=>['egt',0]
    ];
    $page=[
        'list_rows'=>10,
        'next'=>'下一页',
        'prev'=>'上一页'
    ];
</php>
<portal:articles item="vo" where="$where" order="post.create_time DESC" page="$page" relation="categories" categoryIds="$category.id" returnVarName="articles_data">
</portal:articles>

但是用这个,一直用不了,就自己重新写了一个:修改 ListController.class 类:

class ListController extends HomeBaseController{
    public function index(){
        $id = $this->request->param('id', 0, 'intval');            
        $portalCategoryModel = new PortalCategoryModel();
        $category = $portalCategoryModel->where('id', $id)->where('status', 1)->find();
        // 获取当前栏目下的所有子栏目ID
        $category_list = Db::name('portal_category')->field(array('id','parent_id'))->select();
        $category_arr = array();
        $cur_category_list = array();
        array_push($cur_category_list,intval($id));
        foreach($category_list as $v){
            $arr = array();
            $arr['id'] = $v['id'];
            $arr['pid'] = $v['parent_id'];
            array_push($category_arr,$arr);
        }
        //得到当前栏目所有的子栏目ids
        $cur_category_ids = array_merge($cur_category_list,get_all_child($category_arr,$id));
        //获取当前所有子栏目的所有文章ids
        $all_post_ids_arr = array();
        $all_post_ids = Db::name('portal_category_post')->where('category_id','in',$cur_category_ids)->field(array('post_id'))->select();
        foreach($all_post_ids as $v){
            array_push($all_post_ids_arr,$v['post_id']);
        }        
        // 获取当前栏目及子栏目所有的文章列表
        $where = array();
        $where['id'] = array('in',$all_post_ids_arr);
        $where['post_type'] = 1;
        $where['post_status'] = 1;
        $pagelist_arr = Db::name('portal_post')->where($where)->paginate(12);
        $page = $pagelist_arr->render();
        // 处理跳转链接 和 栏目的图片
        $pagelist = array();
        foreach($pagelist_arr as $k => $v){
            $v['thumb'] = '/upload/'.json_decode($v['more'],true)['thumbnail'];
            $v['category_id'] = $this->get_category_id($v['id']);
            array_push($pagelist,$v);
        }
        $this->assign('pagelist',$pagelist);    
        $this->assign('category', $category);
        $this->assign('page', $page);
        $listTpl = empty($category['list_tpl']) ? 'list' : $category['list_tpl'];
        return $this->fetch('/' . $listTpl);
    }
    /*
     * get_category_id 根据文章的id 获取栏目 category_id
     */
    private function get_category_id($id){
        $categoryinfo = Db::name('portal_category_post')->where('post_id','eq',$id)->field('category_id')->find(); 
        return $categoryinfo['category_id'];
    }
}

具体使用:

<foreach name="pagelist" item="v">
<dl class="caselist">
    <dt class="ab"><a href="{:cmf_url('portal/Article/index',array('id'=>$v['id'],'cid'=>$v['category_id']))}"><img src="__ROOT__{$v['thumb']}" alt="" width="285" height="190"></a></dt>
    <dd class="info">
        <a href="{:cmf_url('portal/Article/index',array('id'=>$v['id'],'cid'=>$v['category_id']))}">{$v['post_title']}</a>
        <a href="{:cmf_url('portal/Article/index',array('id'=>$v['id'],'cid'=>$v['category_id']))}">企业官网</a>
    </dd>
</dl>
</foreach> 
<div class="pagination tc">
{$page}
</div>

 

转载于:https://www.cnblogs.com/e0yu/p/9540734.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值