How to filter and display content according to different conditions (category, model, recommendation attributes) for the AnQiCMS document list tag `archiveList`?

Calendar 👁️ 73

When building a website with AnQi CMS, flexibly displaying content is the key to achieving excellent user experience and efficient content management. Among them,archiveListLabels are undoubtedly the core tool for content display, they can help us filter and present articles, products, or other custom content model data according to various conditions. This article will delve deeper.archiveListHow tags can accurately filter and display the content you want based on categories, content models, recommendation attributes, and other conditions.

Flexible control of content display:archiveListThe core role of tags

archiveListThe tag is a powerful tag used to retrieve document lists in Anqi CMS template.No matter where you want to display the latest articles on the homepage, list specific products on the category page, or recommend popular content in the sidebar, it can meet your needs through rich parameter configuration.

{% archiveList archives with type="list" limit="10" %}
    {% for item in archives %}
        <!-- 在这里展示您的内容 -->
        <a href="{{ item.Link }}">{{ item.Title }}</a>
    {% endfor %}
{% endarchiveList %}

here,archivesIs the variable name you defined,type="list"Indicates retrieving a normal list,limit="10"then limits the display to 10 items. Next, we will see how to achieve more refined content filtering through more parameters.

Precisely filter content by category

Categories are the foundation for organizing website content.archiveListTags providedcategoryIdandexcludeCategoryIdParameters, allowing you to easily filter content by category.

If you want to display all content under a specific category, just usecategoryIdThe parameter specifies the category ID. For example, to display the articles under the 'Company News' category with ID 10:

{% archiveList latestNews with categoryId="10" type="list" limit="5" %}
    {% for news in latestNews %}
        <p><a href="{{ news.Link }}">{{ news.Title }}</a></p>
    {% endfor %}
{% endarchiveList %}

If your content is distributed across multiple discontinuous categories,categoryIdIt also supports specifying multiple category IDs separated by commas, for examplecategoryId="10,12,15".

On the contrary, if you want to list all the content of the website but exclude the content under some or certain categories, you can useexcludeCategoryIdFor example, if you want to exclude the "Company News" category from the "All Articles" list, you can set it like this:

{% archiveList allArticles with excludeCategoryId="10" type="list" limit="10" %}
    {% for article in allArticles %}
        <h4><a href="{{ article.Link }}">{{ article.Title }}</a></h4>
    {% endfor %}
{% endarchiveList %}

Moreover, when you are using a category pagearchiveListWhen it is, it will default to reading the current category ID. If you want to explicitly specify not to automatically read the current category ID, or only to display the current category without including the content of its subcategories,childThe parameters come into play.childThe default parameter value istrueIncluding sub-category content. Set it tofalseTo only display the direct content under the current category:

{# 仅显示当前分类下的文档,不包括子分类 #}
{% archiveList currentCategoryDocs with categoryId="0" child=false type="list" limit="10" %}
    {% for doc in currentCategoryDocs %}
        <p>{{ doc.Title }}</p>
    {% endfor %}
{% endarchiveList %}

Please note that whencategoryId="0"then,archiveListIt will not automatically retrieve the category ID from the current page, which can be very useful in some special layouts.

Content structure is defined based on the content model.

The 'Content Model' feature of Anqi CMS is very powerful, allowing you to customize the structure of content, such as defining a 'Article' model, a 'Product' model, or even a 'Case' or 'Service' model.archiveListTag throughmoduleIdParameters can easily be retrieved from a specific content model.

To use this feature, you need to first understand the ID of the content model you need to call.For example, assuming your "article" model has an ID of 1, and your "product" model has an ID of 2.

{# 显示最新的文章,假设文章模型ID为1 #}
<h3>最新文章</h3>
{% archiveList latestArticles with moduleId="1" order="id desc" type="list" limit="5" %}
    {% for article in latestArticles %}
        <p><a href="{{ article.Link }}">{{ article.Title }}</a></p>
    {% endfor %}
{% endarchiveList %}

{# 显示推荐的产品,假设产品模型ID为2 #}
<h3>推荐产品</h3>
{% archiveList recommendedProducts with moduleId="2" flag="c" order="id desc" type="list" limit="5" %}
    {% for product in recommendedProducts %}
        <p><a href="{{ product.Link }}">{{ product.Title }}</a></p>
    {% endfor %}
{% endarchiveList %}

BymoduleIdEnsure that you only retrieve and display data that conforms to a specific content structure, which is crucial for building multi-type content websites.

Use recommendation attributes to highlight key content.

On the document publication interface of Anqi CMS, content can be marked with various "recommended attributes", such as "Headline[h]", "Recommended[c]", "Slide[f]", "Special Recommendation[a]", and so on.These properties are designed to highlight specific content flexibly on the website front-end.archiveListlabel'sflagandexcludeFlagThe parameter is used to filter using these properties.

If you want to display content marked as 'slide' in a certain area of the website (such as the homepage carousel), you can do this:

{# 显示标记为“幻灯”的内容,假设属性为f #}
<div class="slideshow">
    {% archiveList slideshowItems with flag="f" type="list" limit="5" %}
        {% for item in slideshowItems %}
            <img src="{{ item.Thumb }}" alt="{{ item.Title }}">
            <h3>{{ item.Title }}</h3>
        {% endfor %}
    {% endarchiveList %}
</div>

flagThe parameter can specify a letter or letters for recommended attributes (for exampleflag="c"indicating a recommendationflag="h,f"indicating a headline or slide).

Similarly, you can also useexcludeFlagExclude content that has a specific attribute. For example, if you want to list all articles but exclude those that have been set as 'top news', you can write it like this:

{# 显示所有文章,但排除掉“头条”内容 #}
{% archiveList regularArticles with moduleId="1" excludeFlag="h" type="list" limit="10" %}
    {% for article in regularArticles %}
        <p>{{ article.Title }}</p>
    {% endfor %}
{% endarchiveList %}

If you want to see which recommended attributes are marked in the content list in addition to the content itself, you can useshowFlag=truethe parameters. Then, in the loop, by{{item.Flag}}Get and display these properties.

Combine multiple conditions to achieve more flexible content display.

archiveListThe power of tags lies in the ability to combine the various filtering conditions mentioned above, as well as other auxiliary parameters, to build highly customized content lists.

For example, you may need to display the latest five products under the 'Product Model (moduleId=2)' and 'Recommended (flag=c)' categories, which belong to the 'Electronics (categoryId=20)' category, on a 'Product Center' page:

{% archiveList featuredElectronics with moduleId="2" categoryId="20" flag="c" order="id desc" type="list" limit="5" %}
    {% for product in featuredElectronics %}
        <div class="product-card">
            <img src="{{ product.Thumb }}" alt="{{ product.Title }}">
            <h4><a href="{{ product.Link }}">{{ product.Title }}</a></h4>
            <p>{{ product.Description }}</p>
        </div>
    {% endfor %}
{% endarchiveList %}

In addition to the aforementioned core filtering parameters,archiveListother practical parameters are provided:

  • order: control the sorting method of the content, for example,order="id desc"(Sorted by ID in descending order, i.e., the most recent published),order="views desc"(sorted by view count in reverse, i.e., the most popular).
  • limit: Limit the number of displayed content, for examplelimit="10". It also supportsoffsetpattern, such aslimit="2,10"indicating that 10 items start from the 3rd content.
  • type: Determines the type of the list.type="list"Used for normal lists,type="page"Used for lists that require pagination (usually withpaginationtags used together),type="related"Used to retrieve related content (based on the keywords or specified relationships of the current document).
  • q: Used to search for keywords, only intype="page"It takes effect immediately, realizing the in-site search function.
  • combineId/combineFromIdIt is used to add or prepend a document to the list for combined display, which is very useful in scenarios such as travel routes, product comparisons, etc.

By combining these parameters in a clever way, you can easily build dynamic content modules that meet business logic and user needs at any location on the website, greatly enhancing the flexibility of Anqi CMS in content operations.


Frequently Asked Questions (FAQ)

Q1: How do I display all articles under a category on the category page and need pagination functionality?A1: You can usearchiveListLabel, andtypethe parameter topage. For example:{% archiveList articles with type="page" limit="10" %}. This tag will default to reading the current category ID. Then, you also need to combinepaginationTags to render pagination navigation.

Q2: If my content model has customized additional fields, I can usearchiveListDo you filter these custom fields with tags?A2:archiveListTags themselves do not provide custom field filtering parameters directly, but they support filtering through the URL'squeryParameters are filtered, provided that these fields are set as filterable in the additional automatic configuration of the content model. For example, if your content model has a filterablecolorThe field, when the user visitsyourwebsite.com/products?color=redthen,archiveListwill automatically filter according to thecolor=redin the URL.

Q3: How to display a list of content filtered by multiple conditions on a single page, such as 'Latest Articles' and 'Hot Products'?A3: You can completely use multiple on the same pagearchiveListtags. The key is to specify eacharchiveListonedifferentvariable name. For example,{% archiveList latestArticles ... %}and{% archiveList popularProducts ... %}. Each label will independently access and manage its own content list, without interfering with each other.

Related articles

How to configure the pseudo-static rules in AnQiCMS to optimize the URL structure and improve the display of content in search engines?

The importance of URL structure in a content management system is self-evident.A clear, concise, and meaningful URL not only enhances user experience but is also a key factor in search engine optimization (SEO).In AnQiCMS, by carefully configuring the pseudo-static rules, we can transform those dynamic URLs that may have complex parameters into static forms, thereby allowing the website content to display better in search engines.Understanding URL Rewriting: Why It Is Crucial for Your Website?Imagine, a web page address is `www

2025-11-08

How to customize the AnQiCMS content model to meet the display needs of different content types (such as articles, products)?

In today's rapidly changing digital world, website content is no longer just simple articles or product introductions.In order to accurately reach users and improve conversion rates, we often need to tailor the display form and data structure of different types of content to meet their needs.AnQiCMS (AnQi content management system) fully understands this, and the flexible content model function it provides is a powerful tool to solve this challenge.

2025-11-08

How to correctly use the double curly braces `{{}}` and percentage signs `{% %}` tags in AnQiCMS templates to control the display logic of content?

When using AnQiCMS to build and manage websites, flexibly using template language is the key to improving efficiency and achieving personalized display.Among them, the double curly braces `{{}}` and the percentage tags `{% %}` are two core 'roles' that control the display logic of template files.They each have different responsibilities, understanding and using them correctly can help you easily master the powerful template functions of AnQiCMS.

2025-11-08

How to enable Markdown editor in AnQiCMS and display mathematical formulas and flowcharts correctly?

Today, with the increasingly rich content creation, plain text is no longer sufficient to express complex concepts.If complex mathematical formulas in academic articles or clear process diagrams in project management can be presented intuitively on the web, it will undoubtedly greatly enhance the professionalism and user experience of the content.AnQiCMS (AnQiCMS) understands this need, through the built-in Markdown editor and flexible frontend configuration, allowing you to easily implement these advanced content displays.This article will give a detailed introduction on how to enable Markdown editor in AnQiCMS

2025-11-08

How to use AnQiCMS's `archiveDetail` tag to refine the acquisition and display of the detailed content and custom fields of a specified document?

In AnQiCMS, managing and displaying website content, the `archiveDetail` tag is undoubtedly one of the core tools.It allows us to delve into each specific document, whether it is an article, product, or other custom type, thus extracting and presenting its detailed information, even including those custom fields tailored to business needs.Understand and flexibly apply this tag to make our website content more accurate and rich.### `archiveDetail` label's basic and advanced usage When we are on a document detail page

2025-11-08

In Anqi CMS template, how does the `pluralize` filter convert a single word to plural form?

In AnQi CMS template design, we often need to handle the display of different forms of text based on quantity changes, the most common scenario being the singular and plural form conversion of words.Imagine if your website shows '1 article' and '2 articles s', that is clearly unprofessional.To solve this problem, Anqi CMS provides a very practical `pluralize` filter, which can help us easily implement the conversion of plural forms of words in templates, making the expression more natural and intelligent.

2025-11-08

How to use the `pluralize` filter to generate plural forms of common nouns like `customer`, for example `customers`?

It is crucial to use the singular and plural forms of nouns accurately when presenting content on a website, especially when displaying text related to quantities.A subtle grammatical error, such as using the singular form when the quantity is plural, may affect user experience and even reduce the professionalism of the website content. 幸运的是,AnQiCMS provides a very practical tool——`pluralize` filter, which can help us easily solve this problem in the template, ensuring that the content is dynamic and grammatically correct.

2025-11-08

Does the `pluralize` filter support custom plural suffixes? For example, how do I configure it to convert `cherry` to `cherries`?

In website content operation, the accuracy of content and user experience is crucial.Especially when we need to dynamically adjust the singular and plural forms of words according to the quantity, if we handle it manually, it is not only time-consuming and labor-intensive, but also prone to errors.Fortunately, the AnQiCMS template engine provides very convenient filters to solve such problems, among which the `pluralize` filter is a powerful tool.It can automatically add or adjust plural suffixes for words based on numbers, making your website content more smooth and professional.

2025-11-08