织梦CMS调用子栏目时没有子栏目不显示
HTML页面调用标签
{dede:channelartlist} <dl> <!--二级栏目--> <dt class="nav-title"> <a href="{dede:field name='typeurl'/}" style="color:#fff;">{dede:field name='typename'/}</a> </dt> <!--三级栏目--> {dede:channel type='son' noself='yes' } <dd> <a href="[field:typelink/]">[field:typename/]</a> </dd> {/dede:channel} </dl> {/dede:channelartlist}
修改织梦文件
打开:include\taglib\channel.lib.php文件。找到下面的代码
$needRel = false; $dtp2 = new DedeTagParse(); $dtp2->SetNameSpace('field','[',']'); $dtp2->LoadSource($innertext); //检查是否有子栏目,并返回rel提示(用于二级菜单) if(preg_match('#:rel#', $innertext)) $needRel = true; if(empty($sql)) return ''; $dsql->SetQuery($sql); $dsql->Execute(); $totalRow = $dsql->GetTotalRow(); //如果用子栏目模式,当没有子栏目时显示同级栏目 //===================================================修改这里================================ if($type=='son' && $reid!=0 && $totalRow==0 ) //=============================================================================================== { $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line "; $dsql->SetQuery($sql); $dsql->Execute(); } $GLOBALS['autoindex'] = 0;
修改成
$needRel = false; $dtp2 = new DedeTagParse(); $dtp2->SetNameSpace('field','[',']'); $dtp2->LoadSource($innertext); //检查是否有子栏目,并返回rel提示(用于二级菜单) if(preg_match('#:rel#', $innertext)) $needRel = true; if(empty($sql)) return ''; $dsql->SetQuery($sql); $dsql->Execute(); $totalRow = $dsql->GetTotalRow(); //如果用子栏目模式,当没有子栏目时显示同级栏目 //==========================================多添加一个&& $noself=='' 条件 if($type=='son' && $reid!=0 && $totalRow==0 && $noself=='') { $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line "; $dsql->SetQuery($sql); $dsql->Execute(); } $GLOBALS['autoindex'] = 0;