AnQiCMS relies on its powerful template features to provide a solid foundation for flexible display of website content.In website operation, we often encounter the need to display a list of documents under specific categories, such as news updates, product introductions, blog articles, etc.Mastering how to use template tags to achieve this feature will greatly enhance the organization efficiency and user experience of the website content.
Core tags:archiveListuses
In AnQi CMS, the core tag to get a document list under a specific category isarchiveListIt acts as a content filter, capable of accurately extracting the documents you need from the website content library based on the conditions you set.archiveListThe basic structure of using tags is as follows:
{% archiveList 变量名称 with 参数1="值1" 参数2="值2" %}
{# 在这里循环输出文档内容 #}
{% endarchiveList %}
Among them,变量名称This is a temporary name you have set for the document list you have obtained, for convenience in referencing it in subsequent template code.
Key parameter parsing
In order toarchiveListTag accurately understands your intention, we need to use a series of parameters to refine the filtering conditions:
categoryIdThis is the core parameter of the specified category.You can specify which categories' documents you want to retrieve by providing one or more category IDs.categoryId="1"If you need to retrieve documents under multiple categories with IDs 1, 2, and 3 at the same time, just separate the IDs with commas:categoryId="1,2,3"It is worth noting that if your template is currently on a category page (such as the "Company News" category page),archiveListGenerally, it will intelligently recognize the current category ID, at which point you can omit it.categoryIdBut if you want to explicitly not automatically read the current category ID, or to get a category ID that is not related to the current page, you can set it tocategoryId="0".moduleIdThe 'AnQi CMS' supports various content models such as articles, products, etc. This parameter is used to specify which model's documents you want to retrieve. For example,moduleId="1"usually corresponds to the article model,moduleId="2"May correspond to a product model.These model IDs can be viewed and managed in the 'Content Management' -> 'Content Model' section of the Anqi CMS backend, specifying them clearly helps ensure that the correct type of content is obtained.typeThis parameter determines the output style of the document list, the two most commonly used values are"list"and"page".- When
type="list"whenarchiveListwill be according to what you have specified throughlimitThe number of parameters set, directly outputs the document list without pagination processing. This is very suitable for displaying a small number of popular, latest, or recommended documents on the homepage, sidebar, or bottom area of the website. - When
type="page"whenarchiveListThis will generate pagination data for the document list. This means you can combinepaginationtags to provide users with a complete pagination browsing experience including 'Previous page', 'Next page', and page numbers.
- When
limit: Used to control how many documents you want to display. For example,limit="10"means that 10 documents will be displayed.limitThe parameter also supports an "offset" mode, for examplelimit="2,10"The system will skip the first 2 documents (index starts from 0) and then retrieve the next 10 documents.This is very practical in certain specific content layout or personalized recommendation scenarios.order: The sorting method of the document. You can choose different sorting rules according to your needs, such asorder="id desc"represents sorting by document ID in descending order (usually representing the most recent release),order="views desc"representing in descending order by view count (most popular), ororder="sort desc"(sorted by custom sorting on the backend) etc.flagIf you have set recommended attributes (such as "头条[h]", "推荐[c]", "幻灯[f]", etc.) for the document in the background,flagParameters can be used to filter documents with specific properties. For example,flag="c"Only documents marked as "Recommended" will be displayed.
Practical operation examples
To better understand the application of these parameters, let's look at several actual scenarios:
Scenario 1: Display the latest 5 documents under the 'Company News' category on the homepage
Assuming the ID for the 'Company News' category is 5 and the article model ID is 1.
<div class="news-section">
<h3>公司新闻</h3>
<ul>
{% archiveList latestNews with moduleId="1" categoryId="5" order="id desc" limit="5" %}
{% for item in latestNews %}
<li>
<a href="{{ item.Link }}">
<h4>{{ item.Title }}</h4>
<p>{{ item.Description|truncatechars:80 }}</p> {# 截取描述前80个字符,增加易读性 #}
<span>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
</a>
</li>
{% empty %} {# 如果没有文档,显示此内容 #}
<li>暂无新闻动态。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>