How to filter and display the document list of a specified category or model with the `archiveList` tag in AnQiCMS?

Calendar 👁️ 67

AnQiCMS as an efficient enterprise-level content management system, provides users with flexible and diverse content management and display capabilities.When building a website, we often need to display document lists based on specific conditions, such as only showing articles in a certain category, or only listing entries of specific content models (such as products, services). At this point,archiveListTags have become the tool in our hands. They are not only powerful but also very intuitive to use, making it easy for us to meet these needs.

archiveList: Get the core tags of the document list

archiveListThe tag is used in the AnQiCMS template system to query and display the list of 'documents'.Here, the term "document" is a general concept, which can be articles on your website, product information, news updates, or even any entries in a custom content model.Through flexible configurationarchiveListThe parameter, we can accurately control which content needs to be displayed.

Its basic usage is usually like this:

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

Amongst which, "variable name" is a custom name we use for the document list obtained, for examplearticlesorproducts, later inforthe loop you can pass throughitem(or any other loop variable) to access each document data in the list.

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

One of the highlights of AnQiCMS is its flexible content model.You can create different content models based on business needs, such as "article model", "product model", "case model", and so on.When you want to display documents under a specific model only,archiveListlabel'smoduleIdParameters 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, suppose the ID of the "article model" is1And the ID of the 'Product Model' 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 usingmoduleIdis set to1,archiveListit will cleverly only retrieve data from the "article model". Similarly, if you need to display the content under the "product model", just replacemoduleIdwith the corresponding ID.

Filter by category: precisely locate the content range

In addition to filtering by content model, we often encounter the need to display documents based on content categories.For example, on the article list page, we may only want to display all articles under the "CMS Tutorial" category.archiveListofcategoryIdThe parameter is born for this.

You can usecategoryIdSet the ID of a category. For example, if the ID of the "CMS tutorial" category is10You can get 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,separated. 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, and in such cases, we can useexcludeCategoryIdParameter. For example, you want to display all articles but exclude articles with ID10and11Category:

{% 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 subcategory 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 %}

Combine filtering conditions: achieve more complex queries

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

  • Recommended properties (flag): If you have set attributes such as 'Top Story', 'Recommended', 'Slideshow' in the background of the document, you can filter through parameters. For example, display all articles marked as 'Recommended':flagparameter to filter. For example, show all articles tagged 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 arrange the list according to the document ID (newest 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 %}
    
  • Show number (limit): Control how many documents are displayed in the list. You can also useoffset,limitFormat to skip the first few and get a specified number of items. For example, start from the 2nd item and get 5 items:limit="2,5".
  • List type (type): Besides the defaultlistType (fixed number),type="page"Used to cooperatepaginationTags can be used to implement pagination, andtype="related"It is used to get the relevant documents of the current document.
  • When searching for keywords (q):Whentype="page"can be combined withqThe parameter performs keyword search, it will be based on the URL inqThe parameter automatically matches the title

Related articles

How to use the `for` loop tag in AnQiCMS template to iterate and display content list?

In AnQiCMS, efficiently displaying content lists is a core requirement for website operation.Whether it is articles, products, categories, or custom data, we need a flexible mechanism to traverse and present this information.AnQiCMS's powerful template engine provides a `for` loop tag, which acts as a helpful assistant, making it easy for us to achieve this goal.

2025-11-07

How to use the `include` tag in AnQiCMS templates to implement modular display of common components (such as headers and footers)?

When building a website, we often encounter such situations: the header (Header), footer (Footer), and some sidebars, navigation menus, and other components almost appear on every page.If each time these common sections of the code are written repeatedly, not only does it take time and effort, but also once it needs to be modified, it has to be searched and updated on each page, which is inefficient and prone to errors.

2025-11-07

How to define the basic layout in AnQiCMS templates and use the `extends` tag to unify the display style?

When building a website, maintaining a unified page style and clear structure is crucial for improving user experience and development efficiency.AnQiCMS provides a powerful and flexible template engine, which draws on the excellent ideas of Django templates, especially the use of the `extends` tag, making this goal achievable. ### The Foundation of a Unified Style: Basic Layout Template Imagine that your website is like a meticulously designed building, where each room has unique decorations, but the load-bearing walls, roof, and foundation are unified.

2025-11-07

How does AnQiCMS control the timing of content display on the website?

In content operation, the timing of content release is often a key factor in determining its effectiveness.In order to coordinate with marketing activities, meet traffic peaks, or simply to maintain the continuous update of website content, manual timing release not only takes time, but is also prone to errors.AnQiCMS knows this very well, therefore it provides a powerful and easy-to-use scheduled publishing feature, aimed at helping you easily solve the problem of content going live, ensuring that your content is always presented to your target audience at the right moment.When you create new articles, product introductions, or any other documents in the AnQiCMS backend

2025-11-07

How to add pagination and optimize the display effect for document lists in AnQiCMS?

In website operation, how to efficiently display a large amount of content while ensuring the smoothness of user experience is a topic that cannot be ignored.The pagination feature of the document list is the key to solving this problem.AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides intuitive and powerful template tags, allowing you to easily add pagination features to document lists and optimize the display on top of that, making your website content more attractive.

2025-11-07

How to retrieve and display the complete content and properties of a single document using the `archiveDetail` tag?

When using AnQiCMS to build website content, displaying the complete information of a single document is one of the core requirements.No matter whether it is the detailed content of an article, a detailed introduction of a product, or any other specific entry of a custom content model, a highly efficient and flexible way is needed to extract and present this data.This is where the `archiveDetail` tag comes into play.

2025-11-07

How to display the link to the previous and next documents on the AnQiCMS document detail page?

In the ocean of website content, users often hope to browse related information smoothly, not wanting to return to the list to find the next article after reading a wonderful article.This not only affects user experience, but also benefits the internal link structure of the website and search engine optimization (SEO) a lot.AnQiCMS has fully considered this point, providing a convenient and quick navigation function for the content detail page, allowing users to easily navigate between different documents.The AnQiCMS template system is very flexible, it adopts the syntax of the Django template engine

2025-11-07

How does the `relatedArchive` tag display a list of related articles based on document relevance?

In the daily operation of a website, how to make users naturally discover more interesting content after reading an article is the key to improving user experience, extending the time spent on the website, and even optimizing SEO effects.AnQi CMS understands this and provides powerful template tag features, where the `relatedArchive` tag is exactly used to intelligently display related article lists.## `relatedArchive` label

2025-11-07