AnQiCMS (AnQiCMS) lays a solid foundation for the flexible display of website content with its powerful template functions.In website operation, we often encounter the need to display a list of documents under specific categories, such as news, product introductions, blog articles, etc.Mastering how to use template tags to achieve this function will greatly enhance the organization efficiency and user experience of the website content.

Core tags:archiveListusefulness

In Anqi CMS, the core tag to retrieve the document list under a specific category isarchiveList. It acts as a content filter, able to accurately extract the documents you need from the website content library based on your set conditions.archiveListThe basic usage structure of the tag is as follows:

{% archiveList 变量名称 with 参数1="值1" 参数2="值2" %}
    {# 在这里循环输出文档内容 #}
{% endarchiveList %}

Among them,变量名称Is the temporary name you customized for the document list you obtained, convenient for reference in the subsequent template code.

Key parameter parsing

In order toarchiveListThe tag precisely understands your intention, we need to use a series of parameters to refine the filtering conditions:

  • categoryIdThis is the core parameter of the specified category. You can specify the categories under which you want to retrieve documents by providing one or more category IDs.For example, if you want to get the documents under the article category with ID 1, you can write it like this:categoryId="1"If you need to retrieve documents from multiple categories with IDs 1, 2, 3, just separate the IDs with a comma:categoryId="1,2,3"It is worth noting that if your template is currently on a category page (such as the "Company News" category page),archiveListThe system usually intelligently identifies the current category ID, where you can omit itcategoryId. But if you want to explicitly not read the current category ID, or to get a category ID unrelated to the current page, you can set it tocategoryId="0".

  • moduleId: AnQi CMS supports various content models such as articles, products, etc. This parameter is used to specify which model's documents you want to retrieve. For example,moduleId="1"usually corresponds to the article model, whilemoduleId="2"May correspond to a product model. These model IDs can be viewed and managed in the "Content Management" -> "Content Model" on the AnQi CMS backend, specifying them clearly helps ensure that the correct type of content is obtained.

  • typeThis parameter determines the output method of the document list, the two most commonly used values are"list"and"page".

    • Whentype="list"then,archiveListIt will be based on the one you havelimitThe number of parameters set, output the document list directly without pagination processing. This is very suitable for displaying a small number of popular, latest, or recommended documents on the homepage, sidebar, or footer area of a website.
    • Whentype="page"then,archiveListIt will generate pagination data for the document list. This means that you can combinepaginationtags to provide users with a complete pagination browsing experience that includes “Previous page”, “Next page”, and page numbers.
  • limit: Used to control how many documents you want to display. For example,limit="10"it means 10 documents will be displayed.limitThe parameter also supports an “offset” mode, for example,limit="2,10"It indicates that the system will skip the first 2 documents (indexing starts from 0) and then retrieve the next 10 documents.This is very practical in certain specific content layout or personalized recommendation scenarios.

  • order: The document sorting method. You can choose different sorting rules according to your needs, such asorder="id desc"means sorting by document ID in descending order (usually representing the most recent release),order="views desc"representing in descending order of views (most popular), ororder="sort desc"(sorted by backend customization) etc.

  • flagIf you have set recommended attributes for the document in the background (such as "Top[h]", "Recommended[c]", "Slide[f]", etc.), you canflagParameters to filter documents with specific properties. For example,flag="c"Only documents marked as "Recommended" will be displayed.

Practical operation examples

To better understand the application of these parameters, let's look at several actual scenarios:

Scenario one: Display the latest 5 documents under the "Company News" category on the homepage

Assuming the 'Company News' category ID is 5, the article model ID is 1.

<div class="news-section">
    <h3>公司新闻</h3>
    <ul>
    {% archiveList latestNews with moduleId="1" categoryId="5" order="id desc" limit="5" %}
        {% for item in latestNews %}
        <li>
            <a href="{{ item.Link }}">
                <h4>{{ item.Title }}</h4>
                <p>{{ item.Description|truncatechars:80 }}</p> {# 截取描述前80个字符,增加易读性 #}
                <span>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
            </a>
        </li>
        {% empty %} {# 如果没有文档,显示此内容 #}
        <li>暂无新闻动态。</li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

Scenario two