ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# channel 栏目标签 - [栏目标签](#_2) - [格式示例](#_4) - [参数](#_20) - [参数说明](#_39) - [示例](#_227) - [数据字典](#_284) ## 栏目标签 用于调用栏目管理的数据 ## 格式示例 ``` <pre class="calibre16">``` <span class="token5">// 获取顶级菜单栏目</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span> where<span class="token">=</span><span class="token4">"ismenu=1"</span><span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` > 2.1.220504\_202205201800版本起,新增ismenu属性,如下 ``` <pre class="calibre16">``` <span class="token5">// 获取顶级菜单栏目、显示导航栏目菜单</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span> ismenu<span class="token">=</span><span class="token4">"1"</span><span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` ## 参数 参数名称可选值默认值是否必填支持版本说明name栏目ID或变量-type值为peer或son时必填-栏目ID,可以传入变量或指定ID,2.2.3.220920版本起支持多个id,详情见下面参数说明typeson peer top---指定获取的栏目层级 son-获取下级栏目 peer-表示同级栏目 top-表示顶级栏目num例子: 10 或者 10,12---限制结果数量 例如: 10 : 表示获取10条 10,12 : 表从第10开始的12条记录model模型表ID---指定模型IDwhere----数据库查询条件order-weigh desc--排序方式, 格式为 order="字段名称 desc" 其中desc是倒序,asc是升序id-$item--指定循环里的变量名,例如id='obj',模板调用如:{$item.title} 变成 {$obj.title}empty----为空的时候输出提示,支持传入htmlcurrentstyle-active--css class 类名,用于定义当前选中状态样式cache-3600秒--缓存时间,默认3600秒istotal1---统计文档数量ismenu1-->=v2.1.220504显示导航栏目菜单lang--->=v2.2.1.20220603多语言情况下获取指定语言的栏目mod--->=v2.2.1.20220603调用:{$mod} 用于控制偶数输出、换行等,更多查看下面的示例key--->=v2.2.1.20220603指定循环值变量名,默认为$i,从1开始计数每循环一次+1## 参数说明 - `name` 参数通常用于查单条特定的栏目数据。如果type值为peer或son时该值必填,支持变量或数字id 获取栏目ID为3的记录``` <pre class="calibre20">``` <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"3"</span><span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` 根据变量来获取栏目,假设在内容详情页有`$Info`变量,$[Info.categroy.id](http://Info.categroy.id) 是当前文章所属ID,那么我们可以通过这个id来获取栏目同级的栏目代码如下: ``` <pre class="calibre16">``` <span class="token5">// 同级</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"$Info.category.id"</span> type<span class="token">=</span><span class="token4">"peer"</span><span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` 或者使用变量可以获取当前栏目的上级栏目信息 ``` <pre class="calibre16">``` <span class="token5">// $Cate 是当前 栏目的信息该变量在栏目首页、列表页、详情页、单页都存在</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"$Cate.parent_id"</span><span class="token1">}</span> 栏目标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` 2.2.3.220920版本起支持多个id获取栏目。如下,多个栏目ID逗号分隔开 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"1,3,7"</span><span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `type`属性用于获取的栏目层级,如下 1.`son` 获取下级栏目,需要结合name使用 ``` <pre class="calibre16">``` <span class="token5">// 获取栏目ID为1的所有下级菜单</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"1"</span> type<span class="token">=</span><span class="token4">"son"</span> <span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` 2.`peer` 表示同级栏目,需要结合name使用 ``` <pre class="calibre16">``` <span class="token5">// 获取栏目ID为1的所有同级菜单</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"1"</span> type<span class="token">=</span><span class="token4">"peer"</span> <span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` 3.`top` 表示顶级栏目 ``` <pre class="calibre16">``` <span class="token5">// 获取顶级菜单</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span> ismenu<span class="token">=</span><span class="token4">"1"</span> <span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `num` 限制结果数量。例如获取10条栏目那么num="10",当然也支持从第几条开始,例如num="4,2" 表示从第4条获取两条那就是第4条、第五条。 ``` <pre class="calibre16">``` <span class="token5">// 获取顶级栏目从第二条开始获取两条</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span> ismenu<span class="token">=</span><span class="token4">"1"</span> num<span class="token">=</span><span class="token4">"2,3"</span><span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `model`模型id,模型ID在模型管理里面可以看到 ``` <pre class="calibre16">``` <span class="token5">// 获取模型id=1的所有栏目</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel model<span class="token">=</span><span class="token4">"1"</span><span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` ``` <pre class="calibre16">``` <span class="token5">// 使用变量的形式获取顶级栏目</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel model<span class="token">=</span><span class="token4">"$Info.model_id"</span> type<span class="token">=</span><span class="token4">"top"</span><span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `where` 数据库查询条件,语法跟SQL where基本相同。格式:where="字段名 = 1" ,支持传入变量 ``` <pre class="calibre16">``` <span class="token1">{</span><span class="token5">// 获取模型id为1的记录,where条件意思是只显示阅读量大于1的记录}</span> <span class="token1">{</span>hkcms<span class="token1">:</span>content model<span class="token">=</span><span class="token4">"1"</span> where<span class="token">=</span><span class="token4">"views > 1"</span><span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> 描述:<span class="token1">{</span>$item<span class="token1">.</span>description<span class="token1">}</span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>content<span class="token1">}</span> ``` ``` **sql语法可参考:[https://www.w3school.com.cn/sql/sql\_where.asp](https://www.w3school.com.cn/sql/sql_where.asp)** **更多查询表达式参考:[https://www.kancloud.cn/manual/thinkphp6\_0/1037537](https://www.kancloud.cn/manual/thinkphp6_0/1037537)** - `order` 用于字段排序例如上面的代码,格式为order="字段名 asc,字段名2 desc",其中`asc` 表示正序 `desc` 表示倒序,多个排序字段使用逗号分隔开 ``` <pre class="calibre16">``` <span class="token5">// 多个字段排序使用逗号分隔开</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"21"</span> type<span class="token">=</span><span class="token4">"son"</span> order<span class="token">=</span><span class="token4">"weigh asc"</span> <span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `id` 用于改变循环变量默认是$item,例如改成$vo则写成id="vo"无需加$。常用于多个标签嵌套时使用循环变量而不受影响 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"21"</span> type<span class="token">=</span><span class="token4">"son"</span> id<span class="token">=</span><span class="token4">"vo"</span> <span class="token1">}</span> 标题:<span class="token1">{</span>$vo<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `empty`为空提示标签,不支持传入HTML,但可以传入变量 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"111"</span> type<span class="token">=</span><span class="token4">"son"</span> empty<span class="token">=</span><span class="token4">"没有更多数据了"</span> <span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` 传入变量的形式使用html ``` <pre class="calibre16">``` <span class="token1">{</span>php<span class="token1">}</span>$empty <span class="token">=</span> <span class="token4">'<p align="center">- 没有更多数据了 -</p>'</span><span class="token1">;</span><span class="token1">{</span><span class="token">/</span>php<span class="token1">}</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"111"</span> type<span class="token">=</span><span class="token4">"son"</span> empty<span class="token">=</span><span class="token4">"$empty"</span><span class="token1">}</span> <span class="token1">{</span>php<span class="token1">}</span><span class="token6">dump</span><span class="token1">(</span>$item<span class="token1">)</span><span class="token1">{</span><span class="token">/</span>php<span class="token1">}</span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `currentstyle` 当前选中栏目的class样式用于字体高亮等自定义样式、值默认是active ``` <pre class="calibre16">``` <span class="token5">// currentstyle 默认是active,你可以在这指定其他的class</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span> ismenu<span class="token">=</span><span class="token4">"1"</span> currentstyle<span class="token">=</span><span class="token4">"active"</span><span class="token1">}</span> <span class="token5">// 例如:如果当前是新闻中心栏目那么只有新闻中心栏目这条记录有 active 类</span> <span class="token"><</span>li class<span class="token">=</span><span class="token4">"nav-item dropdown {$item.currentstyle}"</span><span class="token">></span> <span class="token"><</span>a class<span class="token">=</span><span class="token4">"nav-link dropdown-toggle"</span> href<span class="token">=</span><span class="token4">"{$item.url}"</span> target<span class="token">=</span><span class="token4">"{$item.target}"</span><span class="token">></span><span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>i class<span class="token">=</span><span class="token4">"fa fa-angle-down"</span><span class="token">></span><span class="token"><</span><span class="token">/</span>i<span class="token">></span><span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token"><</span><span class="token">/</span>li<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `cache` 设置缓存时间单位是秒,系统默认缓存是3600秒,设置成一天:cache="86400" - `istotal` 开启文档数量统计,istotal="1"开启 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"9"</span> type<span class="token">=</span><span class="token4">"son"</span> istotal<span class="token">=</span><span class="token4">"1"</span> <span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> 数量:<span class="token1">{</span>$item<span class="token1">.</span>total<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `ismenu` 显示导航菜单,值为ismenu="1"。在后台栏目管理页面可以控制导航菜单的显示。 ``` <pre class="calibre16">``` <span class="token5">// 获取顶级菜单栏目</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span> ismenu<span class="token">=</span><span class="token4">"1"</span><span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `lang` 指定获取特定语言的栏目,需要开启内容多语言才有效 ``` <pre class="calibre16">``` <span class="token5">// lang="en" 只获取英文不管语言怎么切换都是英文</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"9"</span> lang<span class="token">=</span><span class="token4">"en"</span> <span class="token1">}</span> 标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `mod`属性用于控制一定记录的换行、或增加hr或奇数偶数等标签处理,例如下面的例子每输出5个栏目增加个hr标签 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span> mod<span class="token">=</span><span class="token4">"5"</span><span class="token1">}</span> <span class="token"><</span>p<span class="token">></span>标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span><span class="token"><</span><span class="token">/</span>p<span class="token">></span> <span class="token5">// $mod的值是从1开始的</span> <span class="token1">{</span><span class="token2">if</span> $mod<span class="token">==</span><span class="token3">5</span><span class="token1">}</span> <span class="token"><</span>hr<span class="token">></span> <span class="token1">{</span><span class="token">/</span><span class="token2">if</span><span class="token1">}</span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` mod输出奇数偶数记录,设mod="2",标签内会有$mod变量,里面的值每次计算到2的时候重新计数例如(1,2,1,2,1,2) ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span> mod<span class="token">=</span><span class="token4">"2"</span><span class="token1">}</span> <span class="token1">{</span><span class="token2">if</span> $mod<span class="token">==</span><span class="token3">2</span><span class="token1">}</span> 偶数:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token2">else</span> <span class="token">/</span><span class="token1">}</span> 奇数:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span> <span class="token1">{</span><span class="token">/</span><span class="token2">if</span><span class="token1">}</span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - `key`参数用于指定循环$i的变量,只有标签嵌套时可能需要重新命名$key ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span><span class="token1">}</span> <span class="token5">// $i 是从1开始的。</span> <span class="token"><</span>p<span class="token">></span>序号<span class="token1">{</span>$i<span class="token1">}</span>: <span class="token"><</span>br<span class="token">></span><span class="token"><</span><span class="token">/</span>p<span class="token">></span> <span class="token"><</span>p<span class="token">></span>标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span><span class="token"><</span><span class="token">/</span>p<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` 更改循环变量示例 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span> key<span class="token">=</span><span class="token4">"ii"</span><span class="token1">}</span> <span class="token5">// key="j" 表示这个标签的循环值是{$j},这样就可以避免嵌套的标签依然可以获取外层的标签$ii变量。</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"$item['id']"</span> id<span class="token">=</span><span class="token4">"son"</span> type<span class="token">=</span><span class="token4">"son"</span> key<span class="token">=</span><span class="token4">"j"</span> <span class="token1">}</span> <span class="token"><</span>p<span class="token">></span>外层的循环值:<span class="token1">{</span>$ii<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span><span class="token"><</span><span class="token">/</span>p<span class="token">></span> <span class="token"><</span>p<span class="token">></span>里面这个标签的$值:<span class="token1">{</span>$j<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span><span class="token"><</span><span class="token">/</span>p<span class="token">></span> <span class="token"><</span>p<span class="token">></span>标题:<span class="token1">{</span>$son<span class="token1">.</span>title<span class="token1">}</span> <span class="token"><</span>br<span class="token">></span><span class="token"><</span><span class="token">/</span>p<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` ## 示例 - 多级嵌套获取导航栏的栏目数据 ``` <pre class="calibre16">``` <span class="token5">// type = top, 获取的是顶级栏目。ismenu=1获取导航,在栏目管理里面可以控制导航显示</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span> ismenu<span class="token">=</span><span class="token4">"1"</span><span class="token1">}</span> <span class="token5">// $item 默认的循环变量名,{if}{/if}这是if语句,下面是判断是不是有下级,有下级就显示下拉列表。</span> <span class="token"><</span>li class<span class="token">=</span><span class="token4">"{$item.currentstyle} nav-item {if $item.has_child}dropdown{/if}"</span><span class="token">></span> <span class="token"><</span>a href<span class="token">=</span><span class="token4">"{$item.url}"</span> target<span class="token">=</span><span class="token4">"{$item.target}"</span> class<span class="token">=</span><span class="token4">"nav-link"</span> title<span class="token">=</span><span class="token4">"{$item.title}"</span><span class="token">></span><span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token1">{</span><span class="token2">if</span> $item<span class="token1">.</span>has_child<span class="token1">}</span> <span class="token"><</span>ul class<span class="token">=</span><span class="token4">"dropdown-menu mt-0"</span><span class="token">></span> <span class="token5">// 获取下级栏目,id="son"表示里面的循环变量由默认的$item变成$son,在标签嵌套中这样使用不会影响上级的$item变量</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"$item['id']"</span> id<span class="token">=</span><span class="token4">"son"</span> type<span class="token">=</span><span class="token4">"son"</span> ismenu<span class="token">=</span><span class="token4">"1"</span><span class="token1">}</span> <span class="token"><</span>a href<span class="token">=</span><span class="token4">"{$son.url}"</span> class<span class="token">=</span><span class="token4">"dropdown-item {$son.currentstyle} "</span> title<span class="token">=</span><span class="token4">"{$son.title}"</span><span class="token">></span><span class="token1">{</span>$son<span class="token1">.</span>title<span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> <span class="token"><</span><span class="token">/</span>ul<span class="token">></span> <span class="token1">{</span><span class="token">/</span><span class="token2">if</span><span class="token1">}</span> <span class="token"><</span><span class="token">/</span>li<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - 获取同级栏目示例 ``` <pre class="calibre16">``` <span class="token5">// $Cate是当前栏目的数据,该变量在列表页、内容页、栏目首页模板存在</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"$Cate.id"</span> type<span class="token">=</span><span class="token4">"peer"</span> ismenu<span class="token">=</span><span class="token4">"1"</span> currentstyle<span class="token">=</span><span class="token4">"btn-primary"</span><span class="token1">}</span> <span class="token"><</span>a href<span class="token">=</span><span class="token4">"{$item.url}"</span> class<span class="token">=</span><span class="token4">"btn {$item.currentstyle}"</span><span class="token">></span><span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - 获取指定栏目、以及不存在时显示:暂无数据 ``` <pre class="calibre16">``` <span class="token1">{</span><span class="token5">//获取单条栏目信息}</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"9"</span> empty<span class="token">=</span><span class="token4">"暂无数据"</span><span class="token1">}</span> <span class="token"><</span>h1 class<span class="token">=</span><span class="token4">"title"</span><span class="token">></span>栏目标题:<span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span><span class="token"><</span><span class="token">/</span>h1<span class="token">></span> <span class="token"><</span>p class<span class="token">=</span><span class="token4">"lead"</span><span class="token">></span>栏目描述:<span class="token1">{</span>$item<span class="token1">.</span>seo_desc<span class="token1">}</span><span class="token"><</span><span class="token">/</span>p<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - currentstyle示例:获取当前栏目高亮 效果如下 ![](https://img.kancloud.cn/76/0f/760fb03666840184c63484b07a573cfc_233x225.png) 表示当前栏目是行业资讯,注意:你需要写好定义好class样式。代码示例 ``` <pre class="calibre16">``` <span class="token5">// 显示高亮的class,默认是active</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel type<span class="token">=</span><span class="token4">"top"</span> ismenu<span class="token">=</span><span class="token4">"1"</span> currentstyle<span class="token">=</span><span class="token4">"active"</span> <span class="token1">}</span> <span class="token5">// 只需要在class里面写上{$item.currentstyle},如果是当前栏目会有class="active"</span> <span class="token"><</span>a class<span class="token">=</span><span class="token4">"{$item.currentstyle}"</span> <span class="token">></span><span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` - 排序与统计文档数量 ``` <pre class="calibre16">``` <span class="token5">// 排序 desc-倒序,asc-升序。istotal=1 开启统计文档数量</span> <span class="token1">{</span>hkcms<span class="token1">:</span>channel name<span class="token">=</span><span class="token4">"10"</span> type<span class="token">=</span><span class="token4">"son"</span> cache<span class="token">=</span><span class="token4">"7200"</span> order<span class="token">=</span><span class="token4">"update_time desc"</span> istotal<span class="token">=</span><span class="token4">"1"</span><span class="token1">}</span> <span class="token"><</span>a href<span class="token">=</span><span class="token4">"{$item.url}"</span> class<span class="token">=</span><span class="token4">"btn {$item.currentstyle}"</span><span class="token">></span><span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span> 文档数:<span class="token1">{</span>$item<span class="token1">.</span>total<span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>channel<span class="token1">}</span> ``` ``` ## 数据字典 注意:其中`$item`变量根据channel标签id参数影响,默认是:$item 字段名说明调用方式id栏目ID{$[item.id](http://item.id)}model\_id模型ID{$item.model\_id}parent\_id所属父级栏目ID{$item.parent\_id }type栏目类型,link: 外部链接, list:列表栏目,category:栏目首页{$item.type}name栏目英文名称{$[item.name](http://item.name)}title栏目中文名称{$item.title}url链接地址{$item.url}fullurl带域名的URL地址{$item.fullurl}image栏目缩略图{$item.image}seo\_titleseo标题{$item.seo\_title}seo\_keywordsseo关键字{$item.seo\_keywords}seo\_descseo描述{$item.seo\_desc}ismenu是否是导航菜单,1-导航菜单,0-不是{$item.ismenu}targeta标签跳转方式,用于target="\_blank"属性,有\_blank,\_self等{$item.target}weigh排序{$item.weigh}has\_childtrue 有下级,false 没有下级{$item.has\_child}son\_child数组。拥有的下级栏目ID{$item.son\_child}currentstyle当前选中class,用于CSS文字高亮{$item.currentstyle}parent\_url上级栏目的URL地址{$item.parent\_url}lang语言标识{$item.lang}num列表分页大小{$item.num}