织梦官方默认模版导航菜单的显示为:
主页
{dede:channel type='top' row='10' currentstyle="~typename~"}
[field:typename/]
{/dede:channel}
首先是添加输出二级栏目的代码如下:
主页
{dede:channelartlist typeid='top' currentstyle='on'}
{dede:field name='typename'/}
{dede:channel type='son' noself='yes' currentstyle="~typename~"}
[field:typename/]
{/dede:channel}
{/dede:channelartlist}
这时候如顶级栏目有子栏目,子栏目就会输出并显示出来,如果没有子栏目也不显示子栏目,但是有一个很小的缺点:当顶级栏目没有子栏目时,就会输出多余的的空标签,很少不美观,CSS样式也会影响显示效果,怎样让没有子栏目的时候不显示空白多余的”标签对“ 呢?
首先要判断时候有子栏目,如果下代码:
{dede:field name=typeid runphp="yes"}
global $dsql;
$sql = "SELECT id From `dede_arctype` WHERE reid='@me' And ishidden<>1 order by sortrank asc limit 0, 100 ";
$row = $dsql->GetOne($sql);
@me=is_array($row)?'有下级':'没下级';
{/dede:field}
判断时候有下级的代码木有问题了,但是又有新问题了,织梦中唯一能嵌套的标签是{dede:channelartlist}{/dede:channelartlist},而上面的判断语句代码不能嵌套{dede:channel type=’son’},于是想到上面判断语句输出的字符串替换成包含在子栏目列表的外层的和标签,因为分别在子栏目循环的开始和结束,所以判断语句代码就写了两次,分别在子栏目循环的开始和结束,最终的代码如下:
{dede:channelartlist typeid='top' currentstyle='on'}
{dede:field name='typename'/}
{dede:field name=typeid runphp="yes"}
global $dsql; $sql = "SELECT id From `dede_arctype` WHERE reid='@me' And ishidden<>1 order by sortrank asc limit 0, 100 ";
$row = $dsql->GetOne($sql);
@me=is_array($row)?'':'';
{/dede:field}
{dede:channel type='son' noself='yes' currentstyle="~typename~"}
[field:typename/] ?
{/dede:channel}
{dede:field name=typeid runphp="yes"}
global $dsql;
$sql = "SELECT id From `dede_arctype` WHERE reid='@me' And ishidden<>1 order by sortrank asc limit 0, 100 ";
$row = $dsql->GetOne($sql);
@me=is_array($row)?'':'';
{/dede:field}
{/dede:channelartlist}
方法二;
我们在调用二级菜单的时候,会遇到这样的问题,如果有子栏目,就显示二级菜单,如果没有就不显示,下面给出代码:
{dede:channelartlist row=8 typeid='1,2,3,4,5'}
<li class="tab dropdown">
<a href="{dede:field.typeurl/}" class="tablink arwlink" title="{dede:field.typename/}">{dede:field.typename/}</a>
{dede:field name=typeid runphp="yes"}
global $dsql; $sql = "SELECT id From `dede_arctype` WHERE reid='@me' And ishidden<>1 order by sortrank asc limit 0, 100 ";
$row = $dsql->GetOne($sql);
@me=is_array($row)?'<ul class="subnav">':'';
{/dede:field}
{dede:channel type='son' noself='yes' }
<a href="[field:typeurl/]">[field:typename/]</a>
{/dede:channel}
{dede:field name=typeid runphp="yes"}
global $dsql; $sql = "SELECT id From `dede_arctype` WHERE reid='@me' And ishidden<>1 order by sortrank asc limit 0, 100 ";
$row = $dsql->GetOne($sql);
@me=is_array($row)?'</ul>':'';
{/dede:field}
</li>
{/dede:channelartlist}
Copyright © 2014-2024 牛牛同城企业服务网(www.tcnn.net) 版权所有 网站备案号:苏ICP备16006495号