AnQiCMS as an efficient enterprise-level content management system, provides users with flexible and diverse content management and display capabilities.When building websites, we often need to display document lists based on specific conditions, such as only showing articles under a certain category, or listing entries of specific content models (such as products, services).archiveListLabels have become the sharp weapon in our hands. They are not only powerful in function but also very intuitive to use, enabling us to easily meet these needs.

archiveList: The core label for retrieving document lists

archiveListTags are used in the AnQiCMS template system to query and display the "document" list.The 'document' here is a general concept, which can be articles, product information, news updates, or any entry in a custom content model on your website.archiveListThe parameter allows us to precisely control which content needs to be displayed.

Its basic usage is usually like this:

{% archiveList 变量名称 with 参数="值" %}
    {% for item in 变量名称 %}
        <!-- 在这里显示每个文档的具体信息 -->
    {% endfor %}
{% endarchiveList %}

In which, "variable name" is a custom name we give to the document list we obtain, for example,articlesorproducts, later in,forthe loop, we can useitem[or you can use a custom loop variable] to access each document's data in the list.

Filter by content model: define the boundaries of the content.

AnQiCMS one of the highlights is its flexible content model.You can create different content models according to your business needs, such as "article model", "product model", "case model", and so on.archiveListTagsmoduleIdParameters can be put to good use.

moduleIdThe parameter allows you to specify which content model's document list to retrieve. Each content model has a unique ID in the background. For example, assume the ID of the "article model" is1and the 'product model' ID is2. If you want to display the latest 5 'articles' on the page, you can write it like this:

{% archiveList articles with moduleId=1 limit=5 %}
    {% for item in articles %}
        <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
    {% endfor %}
{% endarchiveList %}

By usingmoduleIdset1,archiveListwill cleverly retrieve data only from the "article model". Similarly, if you need to display content under the "product model", just replace the value with the corresponding ID.moduleIdwith the corresponding ID.

Filter by category: precisely locate content range

We are more often faced with the need to display documents based on content categories, in addition to filtering by content model.For example, on the article list page, we may only want to display all articles under the 'CMS Tutorial' category.archiveListofcategoryIdThe parameters are born for this.

You can setcategoryIdto be the ID of a category. For example, if the ID of the "CMS Tutorial" category is10You can retrieve the document list under this category like this:

{% archiveList tutorialArticles with categoryId=10 limit=10 %}
    {% for item in tutorialArticles %}
        <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
        <p>{{ item.Description }}</p>
    {% endfor %}
{% endarchiveList %}

categoryIdThe parameter supports not only a single category ID, but also multiple category IDs, separated by commas.,[en] Separate. This way, you can display documents from multiple specified categories at once:.

{% archiveList mixedContent with categoryId="10,12,15" limit=10 %}
    {% for item in mixedContent %}
        <p>来自分类ID {{ item.CategoryId }}:<a href="{{ item.Link }}">{{ item.Title }}</a></p>
    {% endfor %}
{% endarchiveList %}

Sometimes, we may need to exclude certain categories, in which case you can use:excludeCategoryIdParameters. For example, you want to display all articles but exclude articles with ID of10and11Category:

{% archiveList allButExcluded with moduleId=1 excludeCategoryId="10,11" limit=10 %}
    {% for item in allButExcluded %}
        <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
    {% endfor %}
{% endarchiveList %}

It is worth mentioning that categories are often hierarchical (with parent categories and subcategories).archiveListThe default setting will display the current category and all its subcategories' documents. If you only want to display the documents directly contained in the current category, and not include the documents of its subcategories, you can setchild=false:

{# 只显示分类ID为10的直接文档,不包含其子分类 #}
{% archiveList directArticles with categoryId=10 child=false limit=10 %}
    {% for item in directArticles %}
        <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
    {% endfor %}
{% endarchiveList %}

Combination filter conditions: Implement more complex queries

archiveListThe strength of it lies in the fact that you can flexibly combine the above filter conditions with other parameters to achieve more refined document queries.

  • Recommended properties (flag)If you have set attributes such as 'Headline', 'Recommended', 'Slideshow' etc. for documents in the background, you can filter them usingflagparameters. For example, to display all articles marked as 'Recommended':
    
    {% archiveList recommendedArticles with moduleId=1 flag="c" limit=5 %}
        {% for item in recommendedArticles %}
            <li><a href="{{ item.Link }}">[推荐] {{ item.Title }}</a></li>
        {% endfor %}
    {% endarchiveList %}
    
  • Sort method (order)You can sort the list by document ID (latest release), views (most popular), or custom sorting on the backend. For example, sort by views in descending order:
    
    {% archiveList hotArticles with moduleId=1 order="views desc" limit=5 %}
        {% for item in hotArticles %}
            <li>{{ item.Title }} ({{ item.Views }} 阅读)</li>
        {% endfor %}
    {% endarchiveList %}
    
  • Display Quantity (limit): Control how many documents are displayed in the list. You can also useoffset,limitFormat to skip the first few and get the specified number. For example, start from the 2nd item and get 5 items:limit="2,5".
  • List type (type): Besides the default typeslistType (fixed number),type="page"For coordinationpaginationtags to implement pagination, andtype="related"it is used to get related documents of the current document.
  • Search keywords (q): whentype="page"When, it can be combinedqto search for keywords by parameters, it will match the title based on the URLqparameters automatically