In website operation, how to efficiently organize and display a large amount of content, and ensure that users can quickly find the information they need, is the key to improving user experience and content value.AnQiCMS provides powerful content management functions, among which the flexible filtering mechanism of the article list can help us easily achieve accurate content presentation.This article will discuss in detail how to filter and display article lists in Anqi CMS through categories, tags, and recommended attributes.


How to accurately display the AnQi CMS article list according to categories, tags, or recommended attributes?

The core value of the content management system lies in the organization and presentation of content.When we accumulate a large amount of articles, products, or other content, if we cannot classify and filter them effectively, it will be difficult for users to quickly find the information they are interested in.The Anqi CMS provides intuitive and powerful template tags, allowing us to flexibly display content lists based on various dimensions such as categories, tags, and recommended attributes.

Core tool:archiveListDocument List Tags

In the template system of Anqi CMS,archiveListTags are the foundation for displaying article lists. They provide rich parameters, allowing us to query and output content based on various conditions.Whether it is a simple list display or a complex scene requiring pagination,archiveListCan all胜任.

In the template file,archiveListTags are usually withforLoop and combine them to iterate through each article found. For example:

{% archiveList archives with moduleId="1" type="page" limit="10" %}
    {% for item in archives %}
        <li><a href="{{item.Link}}">{{item.Title}}</a></li>
    {% empty %}
        <li>暂无内容</li>
    {% endfor %}
{% endarchiveList %}

The above code demonstrates a basic article list,moduleId="1"usually represents the article model (the specific ID needs to be confirmed according to the backend settings),type="page"indicating that the list supports pagination,limit="10"Then it limits the display of 10 articles per page.

Next, we will specifically explain how to apply the core filtering requirements.archiveListTags and their auxiliary tags.

Method one: Filter content by category.

Classification is one of the most basic ways to organize content. In Anqi CMS, we can specify the category of the article, and display the content according to these categories on the front page.

To filter articles by category,archiveListTags providedcategoryIdparameters. You can directly specify one or more category IDs to get the articles under them.

For example, if we want to display all articles under the category with ID 1, we can write it like this:

{% archiveList archives with moduleId="1" categoryId="1" type="page" limit="10" %}
    {% for item in archives %}
        <li><a href="{{item.Link}}">{{item.Title}}</a></li>
    {% endfor %}
{% endarchiveList %}

If you need to display articles for multiple categories (for example, categories with IDs 1, 2, 3), you can separate the category IDs with commas:categoryId="1,2,3". Additionally,childThe parameter (default is true) controls whether to include articles of subcategories. If you only want to display the current category without including its subcategories, you can setchild=false.

In order to make it convenient for users to select categories on the front end, we still need to combinecategoryListtags to display all clickable category navigation:

{% categoryList categories with moduleId="1" parentId="0" %}
    {% for item in categories %}
        <a href="{{item.Link}}">{{item.Title}}</a>
    {% endfor %}
{% endcategoryList %}

After the user clicks the category link, the pseudo-static rule of Anqi CMS will automatically parse the category ID or alias and pass it to the page template,archiveListThe tag can automatically identify the category ID of the current page, no manual setting is requiredcategoryId.

Method two: Filter content by tag

Tags provide a more flexible way to associate content, it does not adhere to a fixed hierarchical structure, and can link articles of different categories and models through a common topic.

AnQi CMS providestagDataListTags are used to retrieve the list of articles under a specified tag.

For example, to display all articles under the tag with ID 5:

{% tagDataList archives with tagId="5" type="page" limit="10" %}
    {% for item in archives %}
        <li><a href="{{item.Link}}">{{item.Title}}</a></li>
    {% endfor %}
{% endtagDataList %}

To get all tags or related tags of the current article, you can usetagListtags. This is very useful for building a hot tag cloud or displaying related tags on the article detail page:

{% tagList tags with limit="10" %}
    {% for item in tags %}
        <a href="{{item.Link}}">{{item.Title}}</a>
    {% endfor %}
{% endtagList %}

Similar to categories, when the user clicks the tag link,tagDataListthe tags can automatically identify the tag ID of the current page.

Method three: filter content according to recommended attributes

The recommendation attribute is a special filtering mechanism that allows operators to mark articles with "recommended", "headlines", "slides", and other tags for prominent display in specific areas of the website.The Anqi CMS backend provides various recommendation attributes (such as: Headline[h], Recommendation[c], Slider[f], etc.).

To filter articles by recommended attributes, just inarchiveListUsed in tagsflagParameter.

For example, to display all articles marked as "recommended":

{% archiveList archives with moduleId="1" flag="c" type="page" limit="10" %}
    {% for item in archives %}
        <li><a href="{{item.Link}}">{{item.Title}}</a></li>
    {% endfor %}
{% endarchiveList %}

You can choose different attribute letters according to your actual needs, such asflag="h"representing the headline,flag="f"Represents a slide. At the same time,