说明:获取当前文档的相关文档。相关文档的逻辑是:根据当前文档的文档id,获取同分类的临近文档。因此该标签只能在文档详情页使用。
使用方法:{% archiveList 变量名称 with type="related" limit="10" %} 如将变量定义为 archives {% archiveList archives with type="related" limit="10" %}...{% endarchiveList %}
type 的值为 related 的情况下,不支持 order 参数。
archives 是一个数组对象,因此需要使用 for 循环来输出
item 为 for循环体内的变量,可用的字段有:
- 文档ID
Id - 文档标题
Title - 文档链接
Link - 文档关键词
Keywords - 文档描述
Description - 文档分类ID
CategoryId - 文档浏览量
Views - 文档封面图片
Images - 文档封面首图
Logo - 文档封面缩略图
Thumb - 文档评论数量
CommentCount - 文档添加时间
CreatedTime时间戳,需要使用格式化时间戳为日期格式{{stampToDate(item.CreatedTime, "2006-01-02")}} - 文档更新时间
UpdatedTime时间戳,需要使用格式化时间戳为日期格式{{stampToDate(item.UpdatedTime, "2006-01-02 15:04:05")}} - 文档标签
- 文档模型设置的其他字段参数
代码示例
获取相关文档标签,只能在文档详情页使用。
{# related 相关文档列表展示 #}
<div>
{% archiveList archives with type="related" limit="10" %}
{% for item in archives %}
<li class="item layui-flex">
<a href="{{item.Link}}" class="link flex-item">
<h5 class="title">{{item.Title}}</h5>
<div class="description">{{item.Description}}</div>
<div class="meta">
<span>{% categoryDetail with name="Title" id=item.CategoryId %}</span>
<span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
<span>{{item.Views}} 阅读</span>
</div>
</a>
{% if item.Thumb %}
<a href="{{item.Link}}" class="thumb">
<img class="thumb-image" alt="{{item.Title}}" src="{{item.Thumb}}">
</a>
{% endif %}
</li>
{% empty %}
<li class="item empty">
该列表没有任何内容
</li>
{% endfor %}
{% endarchiveList %}
</div>