ThinkPHP统计某个分类的文章数目

控制器代码

//统计该类别的文章数目
$cateCount = M('article_category')->where('pid != 0')->count();
$cate = M('article_category')->where('pid != 0')->select();
for($i=0;$i<$cateCount;$i++)
{
    $cate[$i]['count'] = M('article')->where(array('cate_id'=>$cate[$i]['id']))->count();
}
$this->assign('cate',$cate);

模板代码

<ul>
  <volist name="allGroup" id="vo">
      <li><a href="/cate/id/{$vo.id}">{$vo['name']}a>({$vo['count']})li>
  volist>
ul>

article表
ThinkPHP统计某个分类的文章数目_第1张图片

article_category表
ThinkPHP统计某个分类的文章数目_第2张图片


效果图
ThinkPHP统计某个分类的文章数目_第3张图片


本文地址:http://liuyanzhao.com/3583.html

转载请注明

你可能感兴趣的:(PHP)