首先设置一个cids变量,用来存储所有分类id,用当前分类id为初始值:
<php>
$cids=$category['id'];
</php>
利用allSubCategories标签获取当前分类下所有子分类,在portal:allSubCategories标签中,获取所有子分类的ID:
<portal:allSubCategories categoryId="$category.id" item="vo">
<php>
$cids=$cids.",".$vo->id;
</php>
</portal:allSubCategories>
$cids即为当前分类ID和当前子分类ID的集合,比如:
$cids='1,2,5';
获取文章列表:
<portal:articles categoryIds="$cids">
<!--部分参数和内容略-->
<a href="{:cmf_url('portal/Article/index',array('id'=>$vo.id,'cid'=>$vo.category_id))}">
{$vo.post_title}
</a>
</portal:articles>
获取当前分类的子分类列表:
<div class="col-md-3">
<div class="tc-box mycategorys">
<div class="headtitle">
<h2>分类</h2>
</div>
<div class="ranking">
<ul class="list-unstyled">
<portal:subCategories categoryId="$category.id" item="vo">
<li class="top3">
<i>·</i>
<a title="{$vo.name}" href="{:cmf_url('portal/List/index',array('id'=>$vo.id))}">
{$vo.name}
</a>
</li>
</portal:subCategories>
</ul>
</div>
</div>
</div>
如果没有子分类,则隐藏列表:
<script type="text/javascript">
if("{$cids}" == "{$category['id']}") {
$(".mycategorys").hide();
}
</script>