How to call the article list under a specific category in Anqi CMS template?

Calendar 👁️ 60

Managing and displaying content in Anqi CMS is one of its core advantages, and flexibly calling the list of articles under specific categories is an indispensable function in website content operation.No matter if you want to display the latest articles of a special topic on the homepage or show popular recommendations under the current category in the sidebar, Anqi CMS template tags can help you easily achieve it.

The Anqi CMS template system adopts a syntax similar to the Django template engine, which is intuitive and powerful.The core lies in a few key template tags and their parameters, through the combination of these tags, we can precisely control the content that needs to be displayed.

Core Tool:archiveListLabel Exploration

To call the article list in the Anqi CMS template, the most important tag isarchiveListThis tag is like an intelligent filter, which can accurately select the list that meets your conditions from a massive amount of articles.

archiveListThe tag supports various parameters, among which the most closely related to calling the list of articles in a specific category iscategoryIdandmoduleId:

  • categoryId: This is the key parameter for the specified category. You can pass a specific category ID, or multiple category IDs (separated by commas) to get the articles under these categories.
  • moduleId: SecureCMS supports flexible content models, such as 'Article Model', 'Product Model', etc. ThroughmoduleIdparameters, you can specify which content model to retrieve articles from. For example,moduleId="1"typically represents an article model,moduleId="2"may represent a product model.
  • type: This parameter determines the type of article list, it can belist(a simple list),page(a paginated list), orrelated(Related articles).
  • limit: Controls the number of articles returned. For examplelimit="10"It will display the latest 10 articles.
  • order: Specify the sorting method of the articles, such as reverse chronological order by publication time (id desc), Browse in descending order (views desc) and so on.
  • child: A very practical parameter, determines whether to include articles of subcategories.child=true(Default) Includes subcategories,child=falseShow only the articles of the current category.

With a good understanding of the basics, we can start the actual operation.

Actual operation: step by step to implement the list call of specific category articles

The first step is to determine the target category ID

Before calling the list of articles for a specific category, we first need to know the target category ID. There are several ways to obtain it:

  1. Obtained from the backend management interface:Log in to the AnQi CMS backend, go to 'Content Management' -> 'Document Category'.Here, you can find all the categories created, and record the ID of the category you want to call.
  2. Obtained through the URL address:If you are browsing a category page, the URL usually contains the category ID (for example:/category/10.htmlof10It is the category ID).
  3. UsecategoryDetailTag dynamic acquisition:In the template, if you are already in the context of a category (for example, while rendering a category list page), you can pass throughcategoryDetailLabel to get the current category ID. For example:{% categoryDetail with name="Id" %}It will return the current category ID.

Suppose we have explicitly called the ID5Under the 'Company News' category.

Second step: usearchiveListCall the article list

Now, we can pass the category ID intoarchiveListthe tag to get the article list.

Scenario one: Retrieve the latest 10 articles of a specified category (without pagination)

If you only want to display a small number of articles from a category in a specific area (such as the sidebar), you can usetype="list":

{# 假设“公司新闻”分类的ID是5,文章模型ID是1 #}
<div class="news-list">
    <h3>公司新闻</h3>
    <ul>
        {% archiveList articles with categoryId="5" moduleId="1" type="list" limit="10" order="id desc" %}
            {% for article in articles %}
                <li>
                    <a href="{{ article.Link }}" title="{{ article.Title }}">
                        {{ article.Title }}
                    </a>
                    <span>发布于:{{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
                </li>
            {% empty %}
                <li>暂无公司新闻。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

In this example:

  • archiveList articlesAssign the article list obtained toarticlesVariable.
  • categoryId="5"Specified the category ID of the article to be retrieved.
  • moduleId="1"Specified to retrieve content from the article model.
  • type="list": This is a simple article list without pagination.
  • limit="10": Limits to display the latest 10 articles.
  • order="id desc":Sort by article ID in descending order, which usually means the most recently published articles are at the top.
  • {% for article in articles %}:Traversearticleseach article in the variable.
  • {{ article.Link }}and{{ article.Title }}:Retrieve the link and title of the article separately.
  • {{ stampToDate(article.CreatedTime, "2006-01-02") }}:The article's publication timestamp is formatted to the date format of “Year-Month-Day”.
  • {% empty %}:WhenarticlesNo content is displayed in the list.<li>暂无公司新闻。</li>,which is a very friendly user experience.
Scenario two: Dynamically display articles on the category list page and support pagination

When you are on a category page, you usually want to display all the articles under that category and support users to browse through pages. At this time,categoryIdthe value can be dynamically obtained andtypeNeed to be set topage.

{# 假设我们正在一个分类的详情页,当前分类ID可以通过 category.Id 获取 #}
<div class="category-articles">
    <h2>{% categoryDetail with name="Title" %}</h2> {# 显示当前分类标题 #}
    <ul>
        {% archiveList articles with categoryId=category.Id moduleId="1" type="page" limit="15" order="views desc" child=false %}
            {% for article in articles %}
                <li>
                    <a href="{{ article.Link }}" title="{{ article.Title }}">
                        {% if article.Thumb %}
                            <img src="{{ article.Thumb }}" alt="{{ article.Title }}" />
                        {% endif %}
                        <h4>{{ article.Title }}</h4>
                        <p>{{ article.Description|truncatechars:100 }}</p> {# 截取描述前100个字符 #}
                    </a>
                    <div class="article-meta">
                        <span>阅读:{{ article.Views }}</span>
                        <span>{{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
                    </div>
                </li>
            {% empty %}
                <li>此分类下暂无文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>

    {# 分页导航 #}
    <div class="pagination-area">
        {% pagination pages with show="5" %}
            <a href="{{ pages.FirstPage.Link }}" class="{% if pages.FirstPage.IsCurrent %}active{% endif %}">首页</a>
            {% if pages.PrevPage %}<a href="{{ pages.PrevPage.Link }}">上一页</a>{% endif %}
            {% for item in pages.Pages %}
                <a href="{{ item.Link }}" class="{% if item.IsCurrent %}active{% endif %}">{{ item.Name }}</a>
            {% endfor %}
            {% if pages.NextPage %}<a href="{{ pages.NextPage.Link }}">下一页</a>{% endif %}
            <a href="{{ pages.LastPage.Link }}" class="{% if pages.LastPage.IsCurrent %}active{% endif %}">尾页</a>
        {% endpagination %}
    </div>
</div>

In this example:

  • categoryId=category.Id: Dynamically obtain the current category ID.category.IdThis variable is usually provided automatically by the system when accessing the category page, or you can use{% categoryDetail categoryInfo with name="Id" %}to obtain and assign it.categoryInfo.Id.
  • type="page": Pagination feature enabled.
  • limit="15": Displays 15 articles per page.
  • order="views desc": Sorted by views.

Related articles

How to customize the display layout of the article detail page in AnQi CMS?

When building a website with AnQiCMS, we often need to give different types of articles or specific articles a unique appearance and layout to better display the content and enhance the user experience.AnQiCMS provides a flexible mechanism that allows users to customize the display layout of article detail pages according to their needs, whether it is for the entire content model, a specific category, or a single independent article.Understand and make good use of these customization capabilities, it is the key to leveraging the advantages of AnQiCMS content management.The detailed steps to implement the personalized layout of the article detail page will be introduced below

2025-11-08

How to retrieve and display detailed information about website users or user groups (such as VIP level, balance)?

In Anqi CMS, implementing the acquisition and display of detailed information of website users or user groups is a key link in building personalized member systems and enriching user experience.Whether it is to display the user's VIP level, account balance, or the name of the user group they belong to, AnQiCMS provides intuitive and powerful template tags to help us easily achieve these functions. ### Deep Understanding of AnQiCMS User and User Group System AnQiCMS is built with a complete user management and user group (VIP system) function.

2025-11-08

How to customize and output Json-LD structured data in AnQiCMS template to optimize search engine display?

In today's digital marketing environment, the importance of Search Engine Optimization (SEO) is self-evident, and structured data is one of the key factors for improving a website's performance on Search Engine Results Pages (SERP).AnQiCMS is a system focused on providing efficient content management solutions, which offers powerful SEO optimization tools to website operators with its flexible customization and output of Json-LD structured data in templates.

2025-11-08

How to integrate captcha functionality in comment or message form to prevent spam?

Websites and article comments are an important bridge for interaction between websites and users, and they can effectively improve the activity and user stickiness of the content.However, these open interactive areas are often targeted by spammers, and a large amount of meaningless or malicious information not only damages the image of the website but may also affect search engine rankings.To effectively curb such problems, integrating a captcha function into the message or comment form is an effective method.A safe CMS as an efficient website building tool, fully considering common challenges in content operation and providing convenient solutions

2025-11-08

Does AnQi CMS support lazy loading of images in article content?

In a content management system, the loading efficiency of images is crucial for website performance and user experience, especially for articles with many images.Many users may be concerned, does AnQiCMS (AnQiCMS) support lazy loading of images in article content to optimize page loading speed. The answer is affirmative, Anqi CMS **supports** the lazy loading display of images in article content.This is due to its flexible template engine and fine-grained control over content display.Although Anqi CMS itself as a backend content management system does not execute lazy loading logic directly in the browser

2025-11-08

How to set up multilingual content switching display function for Anqi CMS website?

In today's global internet environment, allowing websites to support multiple language displays has become a key step for many enterprises to expand into international markets and serve diverse user groups.AnQiCMS (AnQiCMS) is a powerful content management system that has built-in flexible multilingual support mechanisms to help users easily switch between multilingual displays of website content.To set up multilingual content switching functionality for your Anqi CMS website, we need to understand two main implementation approaches: one is the template-level translation of website interface text**

2025-11-08

How to optimize the URL structure of Anqi CMS to improve search engine display effect?

In website operation, URL structure is one of the key factors affecting search engine visibility and user experience.A clear, logical, and search engine-friendly URL that allows the crawler to better understand the website content, thereby improving the website's ranking in search results.AnQiCMS (AnQiCMS) took this into consideration from the very beginning, providing multiple features to help optimize the URL structure of websites for better search engine display effects. ### Core Function Analysis: How AnQi CMS Creates Friendly URL Structures **1.

2025-11-08

How to implement pagination display of article lists in Anqi CMS?

In a content management system, pagination display of the article list is a basic and important function.It not only effectively manages a large amount of content, improves the loading speed of the website, and avoids users feeling tired from facing an endless scrolling page, but is also a key link in Search Engine Optimization (SEO), helping search engines to better crawl and index website content.For users of AnQiCMS, implementing pagination for the article list is intuitive and powerful, thanks to its flexible and Django-like template engine.The AnQi CMS template system provides us with two core tags

2025-11-08