In managing website content in Anqi CMS, we often need to flexibly control the display of article lists, for example, only showing articles under a specific category on a certain page.This not only helps to organize the website content accurately, but also greatly enhances the browsing experience of visitors, helping them find the information they are interested in more quickly.The AnQi CMS provides powerful template tags, making this requirement simple and intuitive.

The core of achieving this goal lies in the security of the CMS.archiveListThis template tag is the 'universal key' for retrieving article lists from the database. By configuring different parameters, we can precisely filter the desired content.

UnderstandarchiveListThe key parameter of 【en】

InarchiveListIn the tag, there are two crucial parameters used to filter articles of a specific category: 【en】

  • moduleIdThis parameter is used to specify the content model of the article you want to retrieve.In AnQi CMS, articles, products, etc. all belong to different content models.The ID of the 'Article Model' is 1, and the ID of the 'Product Model' is 2. You can view or customize them in the 'Content Management' -> 'Content Model' on the backend.moduleIdIs the first step to obtain the correct list of articles. 【en】
  • categoryIdThis is a key parameter directly specifying the category of the article. By providing one or more category IDs, you can letarchiveListtags return articles under these categories only.

How to get the category ID?

In the applicationcategoryIdBefore the parameters, you need to know the target category ID. There are several common methods to get the category ID:

  1. Get from the backend management interface:The most direct way is to log in to the AnQi CMS backend, go to “Content Management” -> “Document Category”. Here, each category will clearly list its corresponding ID.
  2. Retrieve dynamically through template tags:If you are on a category detail page or its subpage and want to display the articles of the current category, you can usecategoryDetailTo get the current category ID, use the tag and then pass it toarchiveListFor example,{% categoryDetail with name="Id" %}You can directly output the current category ID.

Practical Scenario: Precise Control of Article List

MasteredmoduleIdandcategoryIdAfter we have the parameters and how to obtain the category ID, we can handle various display needs of article lists.

Firstly, assume that you want to display the latest articles under the specific category "Company News" in a certain block of the website.You need to find the ID of the 'Company News' category in the backend (for example, let's assume its ID is 10), and the article model ID is usually 1.archiveListTags:

{% archiveList newsArticles with moduleId="1" categoryId="10" limit="5" %}
    {% for article in newsArticles %}
        <div class="news-item">
            <h4><a href="{{ article.Link }}">{{ article.Title }}</a></h4>
            <p>{{ article.Description }}</p>
            <span>发布日期:{{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
        </div>
    {% else %}
        <p>暂无公司新闻。</p>
    {% endfor %}
{% endarchiveList %}

This code will get the article model(moduleId="1") under the category with ID 10 (categoryId="10"The latest 5 articles in the bracket.

Secondly, if you need to display articles from multiple specific categories in a list at the same time, such as articles from "Company News" (ID: 10) and "Industry Dynamics" (ID: 12), you just need tocategoryIdSeparate these category IDs with commas in the parameter:.

{% archiveList mixedArticles with moduleId="1" categoryId="10,12" limit="10" order="CreatedTime desc" %}
    {% for article in mixedArticles %}
        <div class="article-card">
            <h5><a href="{{ article.Link }}">{{ article.Title }}</a></h5>
            <small>分类: {% categoryDetail with name="Title" id=article.CategoryId %}</small>
            <span> | 日期: {{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
        </div>
    {% else %}
        <p>暂无相关文章。</p>
    {% endfor %}
{% endarchiveList %}

Here,order="CreatedTime desc"The parameter is used to sort articles by publish time in descending order, ensuring that the latest content is displayed.

Again, often we build a page layout that displays content categorized by type, for example, displaying several category titles on the page, and listing several articles under each title. This can be achieved by combiningcategoryListandarchiveListTag implementation:

{% categoryList mainCategories with moduleId="1" parentId="0" %} {# 获取文章模型下的所有顶级分类 #}
    {% for category in mainCategories %}
        <section class="category-block">
            <h2><a href="{{ category.Link }}">{{ category.Title }}</a></h2>
            <ul class="article-list">
                {% archiveList articlesInCategory with moduleId="1" categoryId=category.Id limit="3" %} {# 显示当前分类下的3篇文章 #}
                    {% for article in articlesInCategory %}
                        <li><a href="{{ article.Link }}">{{ article.Title }}</a></li>
                    {% endfor %}
                {% else %}
                    <li>该分类暂无文章。</li>
                {% endarchiveList %}
            </ul>
        </section>
    {% endfor %}
{% endcategoryList %}

In this example,categoryListTraversal of all top-level article categories, and then for each category,archiveListUsecategory.IdParameters are dynamically retrieved and displayed to show the articles under the category.

Finally, if you wish to display all articles under a specific content model but need to exclude one or several specific categories, such as not displaying articles from the category 'Internal Announcement' (ID: 15), the Anqi CMS also providesexcludeCategoryIdParameters to meet this requirement:

{% archiveList allButInternal with moduleId="1" excludeCategoryId="15" limit="10" %}
    {% for article in allButInternal %}
        <div class="general-article-item">
            <h3><a href="{{ article.Link }}">{{ article.Title }}</a></h3>
            <span>分类:{% categoryDetail with name="Title" id=article.CategoryId %}</span>
        </div>
    {% else %}
        <p>暂无文章可显示。</p>
    {% endfor %}
{% endarchiveList %}

This line of code will get all article model contents except for the category with ID 15.

Tips and precautions

In actual operation, please ensure that your template file conforms to the naming and directory structure conventions of the AnQi CMS template, for example, the category list will usually use{模型table}/list.htmlsuch naming format. At the same time,archiveListTags remainlimit(Limit the number of articles),order(Sorting method, such as by publication time, views, etc.) andtype(List type, such as)listUsed for simple lists,pageUsed for pagination list) and more parameters, which can help you further refine the display logic of the article list.Utilize these parameters reasonably to make your website content more organized and professional.

Through these flexible tag combinations and parameter configurations, Anqi CMS allows you to easily manage the content of your website articles, whether it's creating special pages, displaying recommended content, or building complex category navigation, you can do it with ease.


Common Questions (FAQ)

  1. How to determine the article model?moduleIdWhat is it?In most cases, the ID of the 'Article Model' built into the 'Anqi CMS' is 1, and the ID of the 'Product Model' is 2.You can log in to the backend management interface, go to 'Content Management' -> 'Content Model', where you can clearly see each content model and its corresponding ID.If you have customized a new content model, its ID will also be displayed here.

  2. If I want to display the current category and all its subcategories' articles in the article list, do I need to make additional settings?No additional settings are required.archiveListLabels support fetching articles from a specified category and all its subcategories by default. That is to say, when you setcategoryIdWhen a category ID is passed in, it automatically includes all articles under the subcategories of that category. Only when you explicitly do not want to include subcategory articles should you usechild="false"Parameter.

  3. Why did I set it and the article list is still empty or displayed incorrectly?categoryId?This may be caused by several reasons. First, please checkmoduleIdandcategoryIdIs it correct, make sure they match the actual content model and category IDs in the background.Secondly, confirm that there are published (not drafts or in the recycle bin) articles under this category.limitwhether the parameters are set correctly