ClassCMS

导航

使用nav函数获取栏目列表

{loop nav() as $nav}
<a class="{if $nav.active} active{/if}" href="{$nav.link}">{$nav.channelname}</a>
{/loop}

{loop nav() as $nav}
<a class="{if $nav.active} active{/if}" href="{$nav.link}">{$nav.channelname}</a>
栏目循环时亦可输出栏目变量,如:{$nav.keywords},{$nav.content}
{/loop}

{loop nav(2,8) as $nav} {//获取id为2的栏目下属列表,id为0则获取顶级栏目,并限定显示数量为8}
<a class="{if $nav.active} active{/if}" href="{$nav.link}">{$nav.channelname}</a>
{/loop}

{loop nav() as $nav}
    {if $nav.id!=$.0.id}{//不显示首页}
        <a href="{$nav.link}">{$nav.channelname}</a>
    {/if}
{/loop}

从2.0版本开始,nav函数不再返回空链接的栏目

二级导航

{loop nav() as $nav}
    <a href="{$nav.link}" class="{if $nav.active} active{/if}">{$nav.channelname}</a>
    {$navs2=nav($nav.id)}
    {if count($navs2)}
        {loop $navs2 as $nav2} 
            子栏目:<a href="{$nav2.link}" class="{if $nav2.active} active{/if}">{$nav2.channelname}</a>
        {/loop}
    {/if}
{/loop}

通用左侧栏目列表代码

{$navs=nav($.id)}{//获取当前栏目下属栏目列表}
{if count($navs)}{//如果拥有下属栏目}
    子栏目:
        {loop $navs as $nav}
            <a class="{if $nav.active} active{/if}" href="{$nav.link}">{$nav.channelname}</a>
        {/loop}
{elseif $.fid==0}
    {//如果没有下属栏目并且当前栏目是一级栏目,则不显示任何内容}
{else}{//显示兄弟栏目}
  {$navs=nav($.fid)}{//获取兄弟栏目列表}
  {if count($navs)}
    栏目:
        {loop $navs as $nav}
            <a class="{if $nav.active} active{/if}" href="{$nav.link}">{$nav.channelname}</a>
        {/loop}
  {/if}
{/if}

自定义栏目页面新窗口中打开

在需要新窗口打开的的栏目模型中增加target变量(类型为:开关),并且将对应的栏目变量target设置为开

{loop nav() as $nav}
<a class="{if $nav.active} active{/if}" href="{$nav.link}"{if isset($nav.target) && $nav.target}  target="_blank"{/if}>{$nav.channelname}</a>
{/loop}
{//如果设置了栏目变量target,并且target为打开状态时,则在新窗口中打开}