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|不知則問,不能則學!-鄭州金尊国际 » dedecms欄目判斷是否有子欄目,有就顯示,無則不顯示

'); })();