例如内页左侧栏,假如每个一级栏目下都有二级栏目,就用下面这个可以应付。
{pboot:nav parent={sort:pcode} }
{/pboot:nav}
但是遇到一些情况,例如某些一级栏目没有子类就需要用到这个方法了
一、/apps/home/model/ParserModel.php中加入hasSon方法
//当前栏目是否有子栏目,有返回1, 没有返回-1
public function hasSon($scode){
$pcode = $scode;
$result = parent::table('ay_content_sort a')
->where('a.pcode='.$pcode)
->find();
if($result){
return 1;
}else{
return -1;
}
}
二、/apps/home/controller/ParserControlle.php中加入标签代码,共2处
上图加在
// 解析指定分类标签
里面的,注意直接搜“按查询数据条数循环”会有很多个,所以要先定位好
case 'hasSon': //判断指定分类是否有子分类
$hasSon = $this->model->hasSon($value->scode);
$one_html = str_replace($matches2[0][$j],$hasSon,$one_html);
break;
2.public function parserSortLabel($content, $sort)中,添加如下代码
case 'hasSon' ://判断当前分类是否有子分类
$hasSon = $this->model->hasSon($sort->scode);
$content = str_replace($matches[0][$i],$hasSon,$content);
break;
下面是使用例子,注意
{pboot:sort scode={sort:scode}}
{pboot:if({sort:hasSon}>0)}
{pboot:nav parent={sort:scode}}
<a href="[nav:link]" class="onelist textover" {pboot:2if('[nav:scode]'=='{sort:scode}')}style='font-weight:normal'{/pboot:2if}>[nav:name]</a>
{/pboot:nav}
{else}
{pboot:nav parent={sort:pcode}}
<a href="[nav:link]" class="onelist textover" {pboot:2if('[nav:scode]'=='{sort:scode}')}style='font-weight:normal'{/pboot:2if}>[nav:name]</a>
{/pboot:nav}
{/pboot:if}
{/pboot:sort}