dedecms栏目判断是否有子栏目,有就显示,无则不显示

正常调用DEDE下拉菜单含二级栏目如下:

{dede:channelartlist typeid='top' currentstyle='on'}
    {dede:field name='typename'/}
    {dede:channel type='son' noself='yes' currentstyle="~typename~"}
        [field:typename/]
    {/dede:channel}
{/dede:channelartlist}

判断是否有子栏目:

{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 typeid='top'}
            <li>
                <a href="{dede:field%20name='typeurl'/}">{dede:field name='typename'/}</a>
<!-- 上面这部分是调用导航名称和链接,这里有个问题就是,可能有的css样式里面,有2级栏目和没有2级栏目的,父级栏目的样式都有区别,这个代码中没有办法区分 -->
                {dede:field name=typeid runphp="yes"}
                global $dsql; $sql = "SELECT id From `#@__arctype` WHERE reid='@me' And ishidden<>1 order by sortrank asc limit 0, 100 ";
                $row = $dsql->GetOne($sql);
                @me=is_array($row)?'<div class="navshow">':'';
                {/dede:field}
<!-- 上面这部分是输出,如果有2级栏目则输出<div class="navshow">,如果没有则输出空白 -->
                {dede:channel type='son' noself='yes' }
              <a href="[field:typelink/]"><img src="[field:typeimg%20/]"><h2>[field:typename/]</h2></a>
                {/dede:channel}
<!-- 上面这部分是2级栏目的调用代码 -->
                {dede:field name=typeid runphp="yes"}
                global $dsql; $sql = "SELECT id From `#@__arctype` WHERE reid='@me' And ishidden<>1 order by sortrank asc limit 0, 100 ";
                $row = $dsql->GetOne($sql);
                @me=is_array($row)?'</div>':'';
                {/dede:field}
<!-- 上面这部分是输出,如果有2级栏目则输出</div>,如果没有则输出空白,这个其实是输出第一个判断当中,输出样式的结束标签-->
            </li>
{/dede:channelartlist}

下面看一个自己网站写的调用代码:

{dede:channelartlist typeid='top'}

<li class="dropdown margin-left-30"> <a class="dropdown-toggle animation-zoomIn link " data-toggle="dropdown" data-hover="dropdown" aria-expanded="false" role="button"  href="{dede:field%20name='typeurl'/}" >{dede:field name='typename'/}<i class="fa fa-angle-down"></i></a>

                {dede:field name=typeid runphp="yes"}
                global $dsql; $sql = "SELECT id From `#@__arctype` WHERE reid='@me' And ishidden<>1 order by sortrank asc limit 0, 100 ";
                $row = $dsql->GetOne($sql);
                @me=is_array($row)?' <ul class="dropdown-menu dropdown-menu-right bullet " role="menu">':'<ul style="display:none" >';
                {/dede:field}

                {dede:channel type='son' noself='yes' }
            <li class="animation-fade animation-delay-"><a href="[field:typelink/]" class=" animation-fade " title="[field:typename/]">[field:typename/]</a></li>            
                {/dede:channel}

                {dede:field name=typeid runphp="yes"}
                global $dsql; $sql = "SELECT id From `#@__arctype` WHERE reid='@me' And ishidden<>1 order by sortrank asc limit 0, 100 ";
                $row = $dsql->GetOne($sql);
                @me=is_array($row)?'</ul></li>':'</ul></li>';
                {/dede:field}
            
{/dede:channelartlist}

未经允许不得转载:郑州seo|不知则问,不能则学!-郑州seo笔记 » dedecms栏目判断是否有子栏目,有就显示,无则不显示

赞 (5)
'); })();