In AnQi CMS,archiveListThe label is the core tool for dynamically calling and displaying document lists.Whether it is a blog article, product showcase, or news update, this tag can help you flexibly control the display quantity, sorting method, and various filtering conditions according to your specific needs.A deep understanding of its parameters will enable you to build highly customized and powerful content display pages.

Precisely control the number of documents displayed:limitParameter usage

The number of documents in the document list is controlled mainly throughlimitParameters are implemented. It determines how many document data will be displayed each time the call is made.

  • Basic quantity limit: If you want the page to display a fixed number of documents, such as the latest 5 articles published, you can directly setlimit="5".
    
    {% archiveList archives with limit="5" %}
        {# 遍历并显示文档 #}
    {% endarchiveList %}
    
  • Start position and quantity limit (offset mode): When you need to start fetching data from a specific position in a document list, you can use the offset mode. For example, to start from the 3rd document and fetch 10 documents, you can setlimit="2,10"(Please note that the index starts from 0, so 'starting from the third one' means an offset of 2).
  • Combined with pagination.:limitThe parameter withtype="page"Combined, it prepares for pagination functionality. In this mode,limitdefines the number of documents displayed per page, while the actual pagination navigation needs to be配合paginationtags to generate.
    
    {% archiveList archives with type="page" limit="10" %}
        {# 遍历并显示当前页的文档 #}
    {% endarchiveList %}
    {% pagination pages with show="5" %}
        {# 显示分页导航 #}
    {% endpagination %}
    

Flexibly set document sorting:orderThe magic of parameters

orderThe parameter allows you to specify the sorting rules of the document list to meet different content display logic.

  • Sort by ID:order="id desc"Documents are sorted in descending order by document ID, usually used to display the latest documents (the larger the ID, the newer it is). If you want to sort in ascending order, it will beorder="id asc".
  • Sorted by views:order="views desc"Documents are sorted in descending order by the number of views, commonly used to display popular or highly relevant documents.
  • Sorted by custom order in the background.: The AnQi CMS backend allows you to manually adjust the document sorting. At this time, useorder="sort desc"ororder="sort asc"You can display documents according to the custom order set in the backend. If you do not specifyorderParameters, by default, will also be sorted according to the custom sorting of the background (sort desc) performed.

For example, display the top 5 latest articles:

{% archiveList hotArticles with limit="5" order="views desc" %}
    {# 遍历并显示热门文档 #}
{% endarchiveList %}

Precisely filter the document list: multi-dimensional condition setting

archiveListTags provide rich filtering options, helping you accurately lock in the required documents.

  • Filter by content model (moduleId): Anqi CMS supports custom content models, such as "article model", "product model", etc. ThroughmoduleIdParameters, you can specify to only retrieve documents under a specific content model. For example,moduleId="1"Retrieve document model articles,moduleId="2"Retrieve 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 show documents under the category with ID 1. You can pass multiple category IDs, such ascategoryId="1,2,3".
    • excludeCategoryId="4"Exclude documents from the category with ID 4. Also supports multiple IDs.
    • child="true"(Default value): When specifiedcategoryIdInclude documents from all subcategories as well.
    • child="false"When specifiedcategoryIdWhen, only the documents of the current category itself are displayed, without including the subcategories.
    • If you wisharchiveListDo not automatically read the category ID of the current page, you can explicitly set it.categoryId="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, when editing documents, you can set recommended attributes such as 'Headline[h]', 'Recommended[c]', 'Slide[f]', and others.

    • 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": Display recommended document properties in the document list, making it convenient for you to display different properties in the template according to the properties.
    {# 显示所有带有“幻灯”属性的文档 #}
    {% 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 query parameter is already included in the URLq=关键词.archiveListit will automatically read and apply this keyword to search.

    {# 在搜索结果页,显示标题包含“SEO”关键词的文档 #}
    {% archiveList searchResults with type="page" q="SEO" limit="10" %}
        {# ... #}
    {% endarchiveList %}
    
  • Filter by specific user (userId) If you need to display documents published by a specific author or user, you can useuserIdthe parameters. For example,userId="1"