正在加载文档...
文章模板标签
iCMS 文章模板标签使用说明
本文档是由AI基于 ArticleFunc 类的代码分析,以下是 iCMS 系统中文章相关模板标签的详细说明。
如有问题请联系开发人员
ArticleFunc 类
文章应用的标签处理类,继承 AppsFuncCommon 并实现 AppsFuncInterface:
| 方法 | 对应标签 | 功能描述 |
|---|---|---|
| lists | article:list | 获取文章列表 |
| category | article:category | 获取文章分类 |
| data | article:data | 获取文章正文内容 |
| prev | article:prev | 获取上一篇文章 |
| next | article:next | 获取下一篇文章 |
| many | - | 处理多条数据(内部方法) |
NodeFunc 类
节点应用的标签处理类:
| 方法 | 对应标签 | 功能描述 |
|---|---|---|
| lists | node:list | 获取节点列表 |
| data | node:data | 获取节点详情 |
| select | node:select | 生成节点选择器 |
| many | - | 处理多条数据(内部方法) |
参数机制说明
参数传递规则
- 标签中的
参数='值'对应方法中的$vars['参数'] - 多值参数可使用逗号分隔:
id='1,2,3' - 数组参数使用特定格式:
prop[]='field:value'
特殊参数处理
| 参数名 | 类型 | 说明 |
|---|---|---|
| cache | 布尔值 | 是否缓存结果 |
| time | 整数 | 缓存时间(秒) |
| page | 布尔值 | 是否启用分页 |
| row | 整数 | 每页显示条数 |
| loop | 布尔值 | 是否循环输出 |
参数类型说明
- 字符串:直接使用引号包裹
title='标题' - 数字:可以不加引号
id=1或加引号id='1' - 布尔值:使用
1/0表示cache='1' - 数组:使用特殊语法
tag[]='field:value'
文章标签 (ArticleFunc)
article:list 标签
获取文章列表数据。
支持参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| row | 整数 | 10 | 每页显示条数 |
| cache | 布尔值 | 0 | 是否缓存结果 |
| time | 整数 | -1 | 缓存时间(秒) |
| page | 布尔值 | 0 | 是否启用分页 |
| cid/node_id | 整数/字符串 | - | 栏目ID,多个用逗号分隔 |
| cid!/node_id! | 整数/字符串 | - | 排除的栏目ID |
| sub | 布尔值 | 0 | 是否包含子栏目 |
| userid | 整数 | - | 用户ID |
| status | 整数 | 1 | 状态(1:正常 0:草稿) |
| pic | 布尔值 | - | 只显示有图片的文章 |
| nopic | 布尔值 | - | 只显示无图片的文章 |
| weight | 整数 | - | 权重值 |
| startdate | 字符串 | - | 开始日期 |
| enddate | 字符串 | - | 结束日期 |
| orderby | 字符串 | id | 排序字段 |
| by | 字符串 | DESC | 排序方式(ASC/DESC) |
| id | 整数/字符串 | - | 指定文章ID |
| id! | 整数/字符串 | - | 排除的文章ID |
| keyword | 字符串 | - | 关键词搜索 |
| tag | 字符串 | - | 标签 |
| data | 布尔值 | 0 | 是否获取文章内容 |
| body_pics | 布尔值 | 0 | 是否提取内容中的图片 |
| meta | 布尔值 | 0 | 是否获取元数据 |
返回数据结构
[
[
'id' => 文章ID,
'title' => 文章标题,
'description' => 文章描述,
'pic' => [图片信息],
'url' => 文章链接,
'pubdate' => 发布时间,
'hits' => 点击数,
'cid' => 栏目ID,
'tags' => 标签,
'data' => [
'body' => 文章内容
]
],
// 更多文章...
]
使用示例
<!--{iCMS:article:list row='10' loop="true" cid='1' page='1' }-->
<div class="article">
<h3><a href="<!--{$article_list.url}-->"><!--{$article_list.title}--></a></h3>
<div class="desc"><!--{$article_list.description}--></div>
<div class="meta">
<span>发布时间: <!--{$article_list.pubdate|date:'Y-m-d H:i:s'}--></span>
<span>浏览次数: <!--{$article_list.hits}--></span>
</div>
</div>
<!--{iCMSelse}-->
<p class="p-4">暂无相关内容</p>
<!--{/iCMS}-->
<!--{iCMS:pages
page_style='3'
item='<li class="page-item %s">%s</li>'
link='<a class="page-link" href="%s" data-pageno="%d" %s>%s</a>'
}-->
<nav class="mb-4" caria-label="Page navigation">
<ul class="pagination justify-content-center flex-wrap">
<!--{$iCMS.PAGE.NAV}-->
</ul>
</nav>
article:category 标签
获取文章分类数据,实际调用 NodeFunc::node 方法。
支持参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| row | 整数 | 10 | 每页显示条数 |
| cache | 布尔值 | 0 | 是否缓存结果 |
| time | 整数 | -1 | 缓存时间(秒) |
| id | 整数 | - | 分类ID |
| appid | 整数/字符串 | - | 应用ID |
| status | 整数 | 1 | 状态 |
| stype | 字符串 | - | 分类类型(top/sub/suball/self) |
| mode | 字符串 | - | 模式 |
| dir | 字符串 | - | 目录名 |
| rootdir | 字符串 | - | 根目录名 |
| rootid | 整数 | - | 根分类ID |
| meta | 布尔值 | 0 | 是否获取元数据 |
返回数据结构
[
[
'id' => 分类ID,
'name' => 分类名称,
'dir' => 目录名,
'url' => 分类链接,
'pic' => [图片信息],
'description' => 分类描述,
'appid' => 应用ID,
'count' => 文章数量
],
// 更多分类...
]
使用示例
<!--{iCMS:article:category loop="true" stype='top' }-->
<div class="category">
<h3><a href="<!--{$article_category.url}-->"><!--{$article_category.name}--></a></h3>
<p><!--{$article_category.description}--></p>
<p>文章数: <!--{$article_category.count}--></p>
</div>
<!--{/iCMS}-->
article:data 标签
获取文章详细内容数据。
支持参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| aid/article_id | 整数 | - | 文章ID |
| cache | 布尔值 | 0 | 是否缓存结果 |
| time | 整数 | -1 | 缓存时间(秒) |
返回数据结构
[
'article_id' => 文章ID,
'body' => 文章内容,
'subtitle' => 副标题
]
使用示例
<!--{iCMS:article:data aid='1' cache='1'}-->
<div class="article-content">
<h1><!--{$article_data.title}--></h1>
<div class="subtitle"><!--{$article_data.subtitle}--></div>
<div class="content"><!--{$article_data.body}--></div>
</div>
article:prev 标签
获取上一篇文章。
支持参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| id | 整数 | - | 当前文章ID |
| cid | 整数 | - | 栏目ID |
| cache | 布尔值 | 0 | 是否缓存结果 |
| time | 整数 | -1 | 缓存时间(秒) |
返回数据结构
[
'id' => 文章ID,
'title' => 文章标题,
'description' => 文章描述,
'pic' => [图片信息],
'url' => 文章链接
]
使用示例
<!--{iCMS:article:prev id='$article.id' cid='$article.cid' cache='1'}-->
<!--{if $article_prev}-->
<div class="prev-article">
<a href="<!--{$article_prev.url}-->">上一篇: <!--{$article_prev.title}--></a>
</div>
<!--{else}-->
<div class="prev-article">没有上一篇了</div>
<!--{/if}-->
article:next 标签
获取下一篇文章。
支持参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| id | 整数 | - | 当前文章ID |
| cid | 整数 | - | 栏目ID |
| cache | 布尔值 | 0 | 是否缓存结果 |
| time | 整数 | -1 | 缓存时间(秒) |
返回数据结构
[
'id' => 文章ID,
'title' => 文章标题,
'description' => 文章描述,
'pic' => [图片信息],
'url' => 文章链接
]
使用示例
<!--{iCMS:article:next id='$article.id' cid='$article.cid' cache='1'}-->
<!--{if $article_next}-->
<div class="next-article">
<a href="<!--{$article_next.url}-->">下一篇: <!--{$article_next.title}--></a>
</div>
<!--{else}-->
<div class="next-article">没有下一篇了</div>
<!--{/if}-->
节点标签 (NodeFunc)
node:list 标签
获取节点列表数据。
支持参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| row | 整数 | 10 | 每页显示条数 |
| cache | 布尔值 | 0 | 是否缓存结果 |
| time | 整数 | -1 | 缓存时间(秒) |
| id/cid | 整数/字符串 | - | 节点ID,多个用逗号分隔 |
| id!/cid! | 整数/字符串 | - | 排除的节点ID |
| appid | 整数/字符串 | - | 应用ID |
| status | 整数 | 1 | 状态 |
| mode | 字符串 | - | 模式 |
| dir | 字符串 | - | 目录名 |
| rootdir | 字符串 | - | 根目录名 |
| rootid | 整数 | - | 根节点ID |
| rootid! | 整数 | - | 排除的根节点ID |
| stype | 字符串 | - | 节点类型(top/sub/suball/self) |
| meta | 布尔值 | 0 | 是否获取元数据 |
| orderby | 字符串 | sortnum | 排序字段 |
| by | 字符串 | ASC | 排序方式(ASC/DESC) |
返回数据结构
[
[
'id' => 节点ID,
'name' => 节点名称,
'dir' => 目录名,
'url' => 节点链接,
'pic' => [图片信息],
'description' => 节点描述,
'appid' => 应用ID,
'rootid' => 父节点ID,
'sortnum' => 排序值,
'count' => 内容数量
],
// 更多节点...
]
使用示例
<!--{iCMS:node:list loop="1" stype='top' appid='1' cache='1'}-->
<div class="node">
<h3><a href="<!--{$node_list.url}-->"><!--{$node_list.name}--></a></h3>
<p><!--{$node_list.description}--></p>
<!--{if $node_list.pic.url}-->
<img src="<!--{$node_list.pic.url}-->" alt="<!--{$node_list.name}-->">
<!--{/if}-->
</div>
<!--{/iCMS}-->
node:data 标签
获取单个节点详细信息。
支持参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| id | 整数 | - | 节点ID |
| cache | 布尔值 | 0 | 是否缓存结果 |
| time | 整数 | -1 | 缓存时间(秒) |
返回数据结构
[
'id' => 节点ID,
'name' => 节点名称,
'dir' => 目录名,
'url' => 节点链接,
'pic' => [图片信息],
'description' => 节点描述,
'appid' => 应用ID,
'rootid' => 父节点ID,
'sortnum' => 排序值,
'count' => 内容数量,
'config' => [节点配置]
]
使用示例
<!--{iCMS:node:data id='1' cache='1'}-->
<div class="node-detail">
<h1><!--{$node_data.name}--></h1>
<div class="description"><!--{$node_data.description}--></div>
<!--{if $node_data.pic.url}-->
<div class="cover">
<img src="<!--{$node_data.pic.url}-->" alt="<!--{$node_data.name}-->">
</div>
<!--{/if}-->
<div class="meta">
<p>内容数量: <!--{$node_data.count}--></p>
</div>
</div>
node:select 标签
生成节点选择器HTML代码。
支持参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| id | 整数 | 0 | 起始节点ID |
| selected | 整数 | - | 当前选中的节点ID |
| level | 整数 | 1 | 起始层级 |
| appid | 整数 | - | 应用ID |
| as | 布尔值 | 0 | 是否返回HTML而非直接输出 |
返回数据
直接返回HTML代码或者通过变量返回。
使用示例
<select name="cid">
<option value="0">请选择分类</option>
<!--{iCMS:node:select id='0' selected='$article.cid' appid='1'}-->
</select>
通用参数机制
分页参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| page | 布尔值 | 0 | 是否启用分页 |
| row | 整数 | 10 | 每页显示条数 |
| page_style | 字符串 | - | 分页样式 |
| page_ajax | 布尔值 | 0 | 是否使用AJAX分页 |
| page_num | 整数 | - | 指定总页数 |
| page_index | 整数 | - | 指定当前页码 |
| total | 整数 | - | 指定总记录数 |
| total_cache | 布尔值 | 0 | 是否缓存总记录数 |
缓存参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| cache | 布尔值 | 0 | 是否缓存结果 |
| time | 整数 | -1 | 缓存时间(秒) |
| cache_name | 字符串 | - | 自定义缓存名称 |
排序参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| orderby | 字符串 | id | 排序字段 |
| by | 字符串 | DESC | 排序方式(ASC/DESC) |
筛选参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| id | 整数/字符串 | - | 指定ID |
| id! | 整数/字符串 | - | 排除ID |
| where | 数组 | - | 自定义条件 |
| keyword | 字符串 | - | 关键词搜索 |
| keyword_field | 字符串 | title,keywords,description | 搜索字段 |
| keyword_exp | 字符串 | LIKE | 搜索表达式 |
标签嵌套使用规范
嵌套标签示例
<!--{iCMS:article:category stype='top' row='5'}-->
<div class="category">
<h2><a href="<!--{$article_category.url}-->"><!--{$article_category.name}--></a></h2>
<!--{iCMS:article:list cid='$article_category.id' row='3' cache='1'}-->
<ul class="article-list">
<li><a href="<!--{$article_list.url}-->"><!--{$article_list.title}--></a></li>
</ul>
<!--{/iCMS}-->
</div>
<!--{/iCMS}-->
变量传递
在嵌套标签中,可以使用外层标签的变量作为内层标签的参数:
在文章页模板下
<h1><!--{$article.title}--></h1>
<div class="content"><!--{$article.body}--></div>
<!--{iCMS:article:list loop="1" cid='$article.cid' id!='$article.id' row='5' }-->
<div class="related">
<h3>相关文章</h3>
<ul>
<li><a href="<!--{$article_list.url}-->"><!--{$article_list.title}--></a></li>
</ul>
</div>
<!--{/iCMS}-->
最佳实践指南
性能优化建议
-
合理使用缓存
<!--{iCMS:article:list row='10' cache='1' time='3600'}-->⚠️ 对于频繁更新的数据,不建议设置过长的缓存时间。
-
减少数据获取
只获取需要的数据,避免不必要的数据库查询:
<!--{iCMS:article:list row='10' fields='id,title,url' cache='1'}--> -
分页优化
对于大量数据,始终使用分页:
<!--{iCMS:article:list row='20' page='1' cache='1'}--> -
避免深层嵌套
过多的标签嵌套会导致性能下降,尽量减少嵌套层级。
安全规范
避免SQL注入
不要直接使用未经处理的用户输入作为where参数。
调试技巧
-
开启调试模式
<!--{iCMS:article:list db_debug='1'}--> -
查看SQL语句
<!--{iCMS:article:list db_debug='1'}--> <!--{$article_list_sql}--> -
输出变量结构
<!--{$article_list|print_r}-->
高级用法
多参数组合示例
<!--{iCMS:article:list
cid='1,2,3'
sub='1'
status='1'
pic='1'
orderby='hits'
by='DESC'
startdate='2023-01-01'
enddate='2023-12-31'
tag='热门'
row='10'
page='1'
cache='1'
time='3600'
}-->
条件判断
<!--{iCMS:aa:bb }-->
<!-- 内容显示 -->
<!--{iCMSelse}-->
<p>暂无内容</p>
<!--{/iCMS}-->
自定义排序
<!--{iCMS:article:list orderby='pubdate DESC, hits DESC'}-->
数据处理
<!--{foreach key="key" value="value" from="$article_list"}-->
<div class="article">
<h3><!--{$value.title|cut:30}--></h3>
<p><!--{$value.description|cut:100:'...'}--></p>
<span><!--{$value.pubdate|date:'Y-m-d'}--></span>
</div>
<!--{/foreach}-->
总结
iCMS模板标签系统提供了灵活而强大的数据获取和展示机制,通过合理使用标签参数和嵌套结构,可以实现复杂的内容展示需求。在使用过程中,应注意性能优化和安全规范,确保网站运行稳定高效。
⚠️ 注意:本文档基于提供的代码分析生成,实际使用中可能存在更多参数和功能,请参考完整的系统文档。