Manage website content in AnQiCMS, often needing to display relevant information according to different themes or sections.For example, you may wish to display the latest articles under the "Company NewsAnQiCMS provides flexible and powerful template tags, allowing you to easily implement these content call requirements.
Understanding the content organization method of AnQiCMS is the key to efficient use of its functions.The system distinguishes different types of content through "content model", such as article model and product model.Each content model can also create multiple "categories" to further refine the content归属.When you publish articles or products in the AnQiCMS background, you need to assign them to specific content models and categories.This structured content management lays a foundation for our subsequent precise content calls through template tags.
To list the latest articles or products under a specified category, we need to use one of the core template tags of AnQiCMS:archiveListThis tag is like an intelligent filter, which can help us extract data that meets specific conditions from a vast amount of content.
archiveListCore parameters of the tag interpretation
To accurately call the latest content under a specified category, we need to masterarchiveListthe key parameters of the tag:
moduleId: Specify the content typeThis parameter is used to inform the system whether you want to call an article or a product.AnQiCMS defaults to have an article model (usually ID 1) and a product model (usually ID 2).You can view the specific ID of each model in the "Content Management" -> "Content Model" on the backend.moduleId="1"; If you want to display products, set it tomoduleId="2".categoryId: Precisely locate the categoryThis is the core parameter for implementing the 'specified category' call requirement.You need to provide the unique ID of the target category.This ID can be found in the "Content Management" -> "Document Category" section of the AnQiCMS backend.When editing a category, it is usually possible to see the ID of the category in the URL or at some location in the editing interface.categoryId="10".order:Sort rules to ensure “latest”To ensure that the content is “latest”, you need to specify an appropriate sorting method. The two most common options are:order="id desc":By content ID in descending order, usually the larger the ID, the newer the content.order="createdTime desc":According to the creation time of the content in descending order, this can most accurately reflect the "newness" of the content. You can choose one according to your actual needs.
limit: Control the display quantity.This parameter is used to limit how many items are displayed at one time. For example, if you only want to display 5 of the latest articles, you can setlimit="5".typeList display formattypeThe parameter has two main values:type="list":用于简单的内容列表展示,不会涉及分页。type="page":当您希望内容列表支持分页时使用,需要配合。paginationtags to be used.
Practice: Retrieve the latest articles or products under a specified category
Suppose we want to display the 5 latest articles under the "Company News" category on a certain area of the website.
Step 1: Confirm the Classification ID and Model ID
- Log in to the AnQiCMS backend, go to “Content Management” -> “Content Model”, confirm the ID of the “Article Model” (assumed to be
1). - Enter "Content Management" -> "Document Categories", find the "Company News" category, and note its ID (assuming it is
10).
Step 2: Write template code
In your AnQiCMS template file (such as the home page'sindex/index.htmlor the sidebar'spartial/sidebar.htmlIn the parenthesis, you can write code like this:
<div class="latest-news-section">
<h2>公司新闻</h2>
<ul>
{# 使用 archiveList 标签调用指定分类下的最新文章 #}
{# moduleId="1" 表示调用文章模型的内容 #}
{# categoryId="10" 表示只调用ID为10的“公司新闻”分类下的内容 #}
{# order="createdTime desc" 确保内容按发布时间降序排列,即最新内容在前 #}
{# limit="5" 限制只显示最新的5篇文章 #}
{% archiveList latestPosts with moduleId="1" categoryId="10" order="createdTime desc" limit="5" %}
{% for item in latestPosts %}
<li>
<a href="{{ item.Link }}" title="{{ item.Title }}">
{# 如果文章有缩略图,可以显示出来 #}
{% if item.Thumb %}
<img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="news-thumb">
{% endif %}
<span class="news-title">{{ item.Title }}</span>
{# 格式化文章发布时间 #}
<span class="news-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
</a>
</li>
{% empty %}
{# 当该分类下没有内容时,显示此提示 #}
<li><p>该分类下暂无最新文章。</p></li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
This code will iteratearchiveListlatest article list returned. For each article (item),we can obtain its link byitem.Link.item.Titleto get the title,item.ThumbGet the thumbnail,item.CreatedTimeGet publish time