Thinkphp 查询顶级分类下所有文章

2017-08-21  本文已影响0人  microheng
<?php
//根据大分类查询所有分类包括自身的文章
$cid = $cid; //获取分类ID
import('ORG.Util.Page');
// 导入分页类
if($cid != ''){
$map['parent_id']=$cid;
$query1=M('Category_cate')->where($map)->select();  //根据分类ID查询是否有子类
if (count($query1)>0){
$catecid = array($cid); //加入本分类
foreach($query1 as $key) {
$catecid[].=$key["cate_id"]; //循环加入子分类
}
$catecid=implode(',',$catecid); //拆分分类ID
$where['hangye'] = array('in',$catecid);
$count = M('wz')->where($where)->where('shenhe=1')->count();
$Page = new Page($count, 25);
$show = $Page->show();
$num = M('wz')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select(); //获取查询总数
return array($num,$show) ;
}else{
$where['hangye'] = $cid;
$where['shenhe'] = 1;
count = M('wz')->where($where)->where('shenhe=1')->count();
$Page = new Page($count, 25);
$show = $Page->show();
$num = M('wz')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select(); //获取查询总数
return array($num,$show) ;
}
}
?>
上一篇下一篇

猜你喜欢

热点阅读