标签手册
内容标签
内容标签
内容标签用于读取文章列表,是最常用的标签。
内容列表 content
读取文章列表,支持栏目、推荐位、关键词、标签、排序、分页与片段模板;标签本身直接循环,默认变量为 $item、序号为 $i。
调用格式
{pycms:content catid="$category.id" num="8"}...{/pycms:content}
参数
| 参数 | 说明 | 默认 | 取值 / 备注 |
|---|---|---|---|
catid | 栏目 ID | 当前栏目 | 如 $category.id;配合 with_children 包含子栏目 |
num | 输出条数 | 8 | 最大 50;分页模式下表示每页条数 |
page | 是否分页 | 0 | 填 1 开启分页,配合 contentpage 输出分页条 |
order | 排序字段 | 置顶、发布时间倒序 | 支持 id / publish_time / views / is_top / sort |
flag | 推荐位 | 空 | top、recommend、hot、headline,可逗号组合 |
scope | 范围 | 空 | hot 按浏览量、recommend 只取推荐 |
keyword | 关键词 | 空 | 按标题、摘要、标签模糊匹配 |
tag | 标签 | 空 | 按 tags 字段匹配 |
exclude | 排除文章 ID | 空 | 常用于详情页排除当前文章 |
with_children | 包含子栏目 | 0 | 填 1 时连同下级栏目一起查询 |
model_fields | 模型字段 | 0 | 填 1 时列表项注入 model_fields,供 field 标签调用 |
template | 片段模板 | 空 | 每行用指定片段渲染,如 common/post-card |
empty | 空数据提示 | 空 | 无内容时输出的文案 |
id | 循环变量名 | item | 改为 post 后使用 $post.title |
可用字段
$item.id$item.title$item.href / url$item.thumb / image$item.summary / summary_text$item.publish_time / publish_time_text$item.views$item.category.id / title / name / slug / href$item.flags / flags_raw$item.is_top / is_recommend / is_hot / is_headline$item.model_fields
完整示例
<div class="news-list">
{pycms:content catid="$category.id" num="8" order="publish_time desc" empty="暂无内容" id="post"}
<a class="news-item" href="{$post.href}">
{if $post.thumb}<img src="{$post.thumb}" alt="{$post.title}" loading="lazy">{/if}
<h3>{$post.title}</h3>
<p>{$post.summary_text}</p>
<small>{$post.category.title} · {$post.publish_time_text}</small>
</a>
{/pycms:content}
</div>
详情页读取相关文章时加 exclude="$article.id";单标签写法 {pycms:content catid="1" num="6" /} 会输出内置文章列表 HTML。