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

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.