classcms 所有栏目变量的调用方式是怎么样的?
答:
父栏目
{$.fid} 为上级栏目id,根据上级栏目id可以获取上级栏目信息
{$parent=cms:channel:get($.fid)}
父栏目名:{$parent.channelname} 父栏目网址:{$parent.link}
所有父栏目
{$parents=cms:channel:parents($.id)} {//获取当前栏目所有父栏目列表数组}
{loop $parents as $parent}
{$parent.link}/{$parent.channelname}<br>
{/loop}
顶级栏目
{$parents=cms:channel:top($.id)} {//获取当前栏目的顶级栏目,如不存在顶级栏目则返回false}
顶级栏目名:{$parents.channelname}
顶级栏目网址:{$parents.link}
栏目导航
使用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}
<br><a href="{$nav.link}" class="{if $nav.active} active{/if}">{$nav.channelname}</a>
{loop nav($nav.id) as $nav2}
子栏目:<a href="{$nav2.link}" class="{if $nav2.active} active{/if}">{$nav2.channelname}</a>
{/loop}
{/loop}
先判断是否有子栏目后再循环输出子栏目:
{loop nav() as $nav}
<a href="{$nav.link}" class="{if $nav.active} active{/if}">{$nav.channelname}</a>
{$nav2s=nav($nav.id)}
{if count($nav2s)}
子栏目:
{loop $nav2s as $nav2}
<a href="{$nav2.link}" class="{if $nav2.active} active{/if}">{$nav2.channelname}</a> |
{/loop}
{/if}
<br>
{/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}
面包屑
自动自带bread函数,用来获取栏目面包屑导航.
当前栏目面包屑导航
{loop bread() as $bread}
<a href="{$bread.link}">{$bread.channelname}</a>
{/loop}
判断是否为首页:
{loop bread() as $key=>$bread}
{if $key}
<a href="{$bread.link}">{$bread.channelname}</a>
{else}
第一项: <span>{$bread.channelname}</span>
{/if}
{/loop}
判断最后一个栏目:
{$breads=bread()}
{loop $breads as $key=>$bread}
{$breadkeys=array_keys($breads)}
{if end($breadkeys)==$key}
最后一项:<span>{$bread.channelname}</span>
{else}
<a href="{$bread.link}">{$bread.channelname}</a>
{/if}
{/loop}
希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 lecms, classcms, fastadmin, pbootcms, phpcms, eyoucms, yzmcms, xunruicms, jizhicms, wordpress, hkcms, yzncms, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。