In the Anqi CMS,archiveListLabels are the core tools used for dynamically calling and displaying document lists.Whether it is a blog post, product showcase, or news update, this tag can help you flexibly control the number of documents displayed, sorting method, and various filtering conditions according to specific requirements.Deeply understanding its various parameters will enable you to build highly customizable and powerful content display pages.
Precisely control the number of document displays:limitThe application of parameters
The number of documents in the document list is controlled mainly throughlimitParameters. It determines how many document data items will be displayed each time the call is made.
- Basic number limitIf you want the page to display a fixed number of documents, such as the latest 5 articles released, you can directly set
limit="5".{% archiveList archives with limit="5" %} {# 遍历并显示文档 #} {% endarchiveList %} - The starting position and quantity limit (offset mode)When you need to start retrieving data from a specific position in a document list, you can use the offset mode. For example, to start from the 3rd document and retrieve 10 documents, you can set
limit="2,10"Please note that the index starts from 0, so 'starting from the third' means an offset of 2. - Combined with pagination:
limitParameters withtype="page"When used together, it prepares for the pagination feature. In this mode,limitdefines the number of documents displayed per page, and the actual pagination navigation needs to be配合paginationtags to generate.{% archiveList archives with type="page" limit="10" %} {# 遍历并显示当前页的文档 #} {% endarchiveList %} {% pagination pages with show="5" %} {# 显示分页导航 #} {% endpagination %}
Flexible document sorting settings:orderThe clever use of parameters
orderParameters allow you to specify the sorting rules for the document list to meet different content display logic.
- Sort by ID:
order="id desc"The documents will be sorted in descending order by document ID, usually used to display the latest documents (the larger the ID, the more recent it is). If you want to sort in ascending order, it isorder="id asc". - Sort by view count:
order="views desc"Sorted by the document's viewing volume in descending order, commonly used to display popular or highly concerned documents. - Sorted according to custom sorting in the background.:Security CMS backend allows you to manually adjust the document sorting. At this time, use
order="sort desc"ororder="sort asc"documents can be displayed according to the custom order you set in the backend. If you do not specifyorderParameter, by default it will also be sorted according to the backend customization (sort desc).
For example, display the latest 5 hot articles:
{% archiveList hotArticles with limit="5" order="views desc" %}
{# 遍历并显示热门文档 #}
{% endarchiveList %}
Accurate filtering of document list: multi-dimensional condition setting
archiveListThe label provides rich filtering conditions to help you accurately lock in the required documents.
Filter by content model (
moduleId): English CMS supports custom content models, such as "article model", "product model", etc. ThroughmoduleIdParameters, you can specify to get documents under a specific content model. For example,moduleId="1"Get article model documents,moduleId="2"Get product model documents.{% archiveList products with moduleId="2" limit="10" %} {# 显示产品列表 #} {% endarchiveList %}Filter by category (
categoryId,excludeCategoryId,child): This is one of the most commonly used filtering methods.categoryId="1":Only display documents under the category with ID 1. Multiple category IDs can be passed in,categoryId="1,2,3".excludeCategoryId="4"Exclude documents under categories with ID 4. Also supports multiple IDs.child="true"(Default value): When specifiedcategoryIdInclude documents under all child categories as well.child="false"When specifiedcategoryIdWhen selected, only documents in the selected category are displayed, not including subcategories.- If you wish to
archiveListDo not automatically read the current page's category ID, and you can explicitly set itcategoryId="0".
{# 显示分类ID为1及其子分类下的最新10篇文章 #} {% archiveList articles with categoryId="1" child="true" order="id desc" limit="10" %} {# ... #} {% endarchiveList %} {# 只显示分类ID为5的文档,不含子分类 #} {% archiveList docs with categoryId="5" child="false" limit="5" %} {# ... #} {% endarchiveList %}Filter by recommended attributes (
flag,excludeFlag,showFlag)In the background editing document, you can set recommended attributes such as 'Top News [h]', 'Recommended [c]', 'Slideshow [f]', etc. for the document.flag="c":Only display documents with the 'recommended' attribute. Can be combined, such asflag="h,c".excludeFlag="s":Exclude documents with the 'scroll' attribute.showFlag="true"In the document list, display the recommended properties of the document, making it convenient for you to show different displays according to the properties in the template.
{# 显示所有带有“幻灯”属性的文档 #} {% archiveList slides with flag="f" limit="3" %} {# ... #} {% endarchiveList %}Filter by search keywords (
q)Whentype="page"mode,qThe parameter can be used to specify the search keyword. It is worth noting that if the URL already containsq=关键词Query parameters,archiveListIt will automatically read and apply this keyword for the search.{# 在搜索结果页,显示标题包含“SEO”关键词的文档 #} {% archiveList searchResults with type="page" q="SEO" limit="10" %} {# ... #} {% endarchiveList %}Filter by a specific user (
userId): If you need to display documents published by a specific author or user,userIdparameters. For example,userId="1"