In AnQiCMS, flexibly displaying content is one of the keys to building an efficient website.archiveListLabels are such a powerful tool that allow us to filter and display the document list of a website based on various conditions. Whether you want to display a certain type of article on a specific page or organize information based on content type or editorial recommendations,archiveListCan provide precise control.

Precise positioning: Filter document list by category ID

When we want to display documents under a specific category in a certain area of a website, such as the sidebar or a special topic page,categoryId参数就派上了用场。这个参数让我们可以指定一个或多个分类的ID,从而精确地提取出这些分类下的所有文档。

For example, if you want to display articles under the "Company News" category with ID 1, you can do it like this:

{% archiveList archives with categoryId="1" limit="5" %}
    {# 在这里循环展示文档 #}
{% endarchiveList %}

If your content spans multiple categories, for example, if you want to display documents under both "Company News" (ID 1) and "Industry News" (ID 3), just separate the IDs with commas:

{% archiveList archives with categoryId="1,3" limit="10" %}
    {# 结合多个分类ID展示文档 #}
{% endarchiveList %}

It is worth noting that AnQiCMS categories can have hierarchical relationships. By default, when you specify a parent category ID,archiveListIt will automatically include all documents under its subcategories. But if you only want to display documents under the current specified category (excluding its subcategories), you can by settingchildparameter settingsfalseThis can be achieved:

{% archiveList archives with categoryId="1" child=false limit="5" %}
    {# 只展示ID为1分类下的文档,不包含其子分类 #}
{% endarchiveList %}

Moreover, in some special page scenarios, we may wantarchiveListnot to automatically inherit the classification ID of the current page, but to be manually specified. At this time, you cancategoryIdset explicitly to"0"To avoid any automatic inheritance behavior.

Content division: Filter document list by model ID

The 'Content Model' feature of AnQiCMS is a reflection of its high flexibility.It allows us to define different types of content structures, such as 'article model', 'product model', and even 'case model', etc.moduleIdThe parameters become particularly important.

By specifyingmoduleIdWe can ensurearchiveListOnly extract documents that belong to a specific content model. For example, if the ID of the "Article Model

想展示最新的5篇“文章”:

{% archiveList articles with moduleId="1" order="id desc" limit="5" %}
    {# 展示最新的5篇文章 #}
{% endarchiveList %}

如果想列出全部的“产品”:

{% archiveList products with moduleId="2" type="page" limit="10" %}
    {# 列出所有产品,并支持分页 #}
{% endarchiveList %}

This way of filtering by model makes the content structure of the website clearer, and it also facilitates differentiated display and management for different content models.

Highlight the key points: Filter the document list based on recommended attributes

In addition to categories and models, AnQiCMS also provides the "recommended attributesflagThe parameter is used to filter by these recommended attributes.

AnQiCMS supports various recommended attributes, each with a corresponding letter identifier, for example:

  • h: Headlines
  • cRecommended
  • f: Slide
  • a: Recommended
  • s: Scroll
  • p: Picture
  • j: Redirect

When you want to display those documents marked as "slide" in the slide area of the homepage, you can set it like thisflagParameters:

{% archiveList slides with flag="f" limit="3" %}
    {# 展示3篇被标记为“幻灯”的文档 #}
{% endarchiveList %}

You can also filter documents with multiple recommended properties at the same time, for example, documents that are both 'recommended' and 'images' (although usually only one main property is used):

{% archiveList featuredImages with flag="c,p" limit="4" %}
    {# 展示4篇既是“推荐”又是“图片”的文档 #}
{% endarchiveList %}

WithflagCorrespondinglyexcludeFlagIf you want to exclude documents with certain recommended properties, such as not displaying any "Top Stories" content, you can use it like this:

{% archiveList regularContent with excludeFlag="h" limit="10" %}
    {# 展示除了“头条”之外的10篇文档 #}
{% endarchiveList %}

Combined use to achieve more refined filtering

archiveListThe power of tags lies in the fact that these filtering conditions are not mutually exclusive but can be used flexibly. By specifying at the same time,categoryId/moduleIdandflagWe can build a very specific list of documents.

For example, if you want to display the latest 10 documents under the "article model

{% archiveList targetedArticles with moduleId="1" categoryId="5" flag="c" order="id desc" limit="10" %}
    {# 精准筛选:文章模型,分类ID为5,推荐属性,最新10篇 #}
{% endarchiveList %}

Additionally, for users who use the AnQiCMS multi-site management feature,siteIdUsing parameters to specify which site's document list to retrieve, ensuring flexibility in calling content in multi-site environments.

By flexibly using these parameters,archiveListLabels can help us precisely control the display of website content, whether it is to enhance user experience or to optimize search engine rankings, it can provide strong support.


Common Questions (FAQ)

1. I want to display the latest documents under a certain category on a single page, and these documents must be of the 'article model'. How should I write it?

You can combinecategoryId/moduleIdandorderParameters to implement. Assuming the category ID is 5, and the article model ID is 1:

{% archiveList recentArticles with categoryId="5" moduleId="1" order="id desc" limit="5" %}
    {# 在这里循环展示最新5篇“文章模型”下的分类5文档 #}
{% endarchiveList %}

2. How to avoidarchiveList自动获取当前页面的分类ID,而是完全按照我指定的ID来筛选?

你可以将categoryIdParameter is explicitly set"0",so thatarchiveListIt will not attempt to read the current page's category information, but will only use the other filtering conditions you manually specify (or do not specify).

{% archiveList myCustomList with categoryId="0" moduleId="1" limit="10" %}
    {# 确保不继承当前页面的分类ID,只展示模型ID为1的文档 #}
{% endarchiveList %}

3. If I want to exclude all documents marked as 'Headline' from a list, and only display content from a specific category, is that possible?

Of course. You can use it simultaneouslycategoryIdandexcludeFlagParameters. Assuming the category ID is 10, the headlines to be excluded areh:

{% archiveList filteredList with categoryId="10" excludeFlag="h" limit="8" %}
    {# 展示分类ID为10,且不是头条的8篇文档 #}
{% endarchiveList %}