How to accurately retrieve and display a specific article list based on category ID?

Calendar 👁️ 71

In a content management system, effectively organizing and displaying content is the key to improving user experience and website SEO performance.AnQi CMS with its flexible and powerful template engine, allows you to easily implement the need to retrieve and display a list of articles based on a specific category ID.Whether it is to build a special page, category archive, or simply to display the latest content of a specific column on the homepage, Anqi CMS can provide an intuitive and efficient solution.

This article will delve into how to utilize the template tag function of Anqi CMS, especiallyarchiveListtags, to achieve this goal accurately.


1. Preliminary preparation: Understand the category ID

Before starting to write the template code, we first need to clarify the ID of the target category.In the AnQi CMS backend, find the 'Document Classification' option under the 'Content Management' menu.Here, you will see a list of all categories created. Each category will have a unique numeric ID (usually visible in the URL or on the detail page when editing).For example, the ID of your 'Company News' category may be '1', and the ID of the 'Product Introduction' category may be '5'.Please note the category ID you need to retrieve the article list, which will be the key for us to call accurately in the template.


Second, core functions:archiveListThe clever use of tags

The template system of Anqi CMS adopts syntax similar to Django, wherearchiveListTags are the core tools for obtaining article lists. They provide rich parameters, allowing you to highly customize the filtering and display of content.

1.archiveListBasic structure of the tag

archiveListTags are usually withforCombine loops to traverse the list of obtained articles. The basic syntax is as follows:

{% archiveList 变量名 with 参数1="值1" 参数2="值2" %}
    {% for item in 变量名 %}
        {# 在这里展示每篇文章的信息 #}
        <a href="{{ item.Link }}">{{ item.Title }}</a>
        {# ... 更多文章详情字段 ... #}
    {% empty %}
        {# 如果没有找到文章,显示此内容 #}
        <p>该分类下暂无文章。</p>
    {% endfor %}
{% endarchiveList %}

Among them,变量名Is customized by you, used to store the obtained list of articles (for examplearticles/newsListetc.).itemIt is a temporary variable for each article in the loop.

2. Detailed explanation of key parameters

In order to accurately obtain articles according to the category ID, we need to pay attention to the following parameters:

  • categoryIdThis is the core parameter for implementing "accurate retrieval according to category ID." You only need to assign the ID of the target category to it. If there are multiple categories, you can use a comma to separate them.,Separate multiple IDs, for examplecategoryId="1,3,5". If you want to list the articles in the current category page (for example, if you are visiting a category list page), you can specify it withoutcategoryIdThe system will automatically read the current category ID; if you want to explicitly not read it and only filter through other parameters, you can set it tocategoryId="0".
  • moduleIdIn AnQi CMS, content is usually attributed to different 'models' (such as article models, product models). To ensure that you are getting an article, it is usually necessary to specifymoduleId="1"(The default ID of the article model). If you are not sure, you can check the ID of the article model in the 'Content Model' management on the backend.
  • limit: Control the number of articles you want to display. For example,limit="10"It will display 10 articles. If you need to skip the first few articles to get the subsequent articles (such as implementing "start displaying 5 articles from the 3rd article"), you can use a comma-separated format, such aslimit="2,5"This indicates that starting from the element at index 2, 5 elements are to be obtained.
  • order: Defines the sorting method of the articles. Common ones include:
    • order="id desc": Sorts by article ID in descending order (the most recently published articles are at the top).
    • order="views desc": Sort by view count in descending order (popular articles first).
    • order="CreatedTime desc": Sort by creation time in descending order (withid descsimilar, more explicit).
  • type: Determines the type of list.
    • type="list"(Default): Get a list of specified number of articles without pagination.
    • type="page": Used for scenarios requiring pagination display, it needs to bepaginationtag usage
  • child: (Default istrue) If you specify a category ID and want to include all articles under the subcategories of that category, keep the default valuechild=truethen. If you only want to getthe current specified category itselfof the article, excluding the articles of its subcategories, then it needs to be explicitly set tochild=false.
  • excludeCategoryId: If you want to get articles under a certain model but want to exclude some specific categories, you can use this parameter. For exampleexcludeCategoryId="2,4"Articles under categories with IDs 2 and 4 will be excluded.

Chapter 3: Practical Scenario: Displaying Article Lists Based on Category ID

Let's look at some actual code examples to see how to display article lists based on different requirements.

1. Show the latest article list of a single category

Assume you want to display the latest 5 articles of "Company News" (category ID 1) in a certain area of the website.

<section class="latest-news">
    <h2>公司新闻</h2>
    <ul>
        {% archiveList news with categoryId="1" moduleId="1" limit="5" order="id desc" %}
            {% for item in news %}
                <li>
                    <a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a>
                    <time datetime="{{ stampToDate(item.CreatedTime, "2006-01-02") }}">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</time>
                </li>
            {% empty %}
                <li>暂无公司新闻。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</section>

Explanation:

  • categoryId="1": Exactly specified the category ID as 1.
  • moduleId="1": Ensure that we are getting the article.
  • limit="5":Limit to displaying only 5 articles.

Related articles

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

In AnQi CMS, managing and displaying content is a core function, and the article detail page, as an important interface for users to obtain information and interact with the website, is directly affected by the display layout and design of the elements, which in turn affects user experience and information communication efficiency.AnQi CMS provides high flexibility, allowing users to deeply customize the display of article detail pages according to their own needs. To customize the article detail page, you first need to understand the Anqi CMS template system.It uses syntax similar to the Django template engine, template files are usually suffixed with .html

2025-11-08

How to flexibly configure the display of "Built-in links", "Category page links", and "External links" in the website navigation?

Website navigation, just like a map for users to explore your website, a clear and efficient navigation can greatly enhance the user experience and help visitors quickly find the information they need.In AnQiCMS, the website navigation configuration provides very high flexibility, allowing you to combine 'built-in links', 'category page links', and 'external links' ingeniously according to your actual needs, and make fine-grained settings. ### Diverse navigation location and hierarchy management In AnQiCMS, you do not have to stick to a fixed navigation menu.You can access the 'Navigation Category Management' feature

2025-11-08

How does image processing in content settings (Webp, large image compression) affect page loading speed and image display quality?

In website operation, images are undoubtedly the key elements that attract users and enrich content.High-quality images can greatly enhance the attractiveness of a page, whether it is for product display, article illustrations, or brand image.However, the size of image files is often a major culprit in slowing down website loading speed.Fortunately, AnQiCMS (AnQiCMS) provides powerful image processing functions in the content settings, such as WebP format conversion and automatic compression of large images, helping us cleverly balance image quality and page loading speed, thereby enhancing the overall user experience and SEO performance.###

2025-11-08

How to optimize search engine crawling and user experience with static rules (such as URL structure)?

In website operation, the URL plays a vital role.A well-designed URL can not only help search engines better understand and crawl the website content, but also significantly improve the user experience.AnQiCMS (AnQiCMS) understands this point, therefore, it has integrated flexible and powerful pseudo-static rules and 301 redirect management functions into its system, allowing website administrators to easily build URL structures that are friendly to both search engines and users. ### Static rules: Why are they so important?Imagine that

2025-11-08

How does Anqi CMS implement seamless language switching and display of multilingual content on the front-end page?

Today, with the deepening of globalization, website content that can reach users of different languages has become a key factor in enterprises expanding the market and enhancing brand influence.AnQiCMS (AnQiCMS) is well aware of this need, and from the very beginning of system design, it has made multilingual support one of its core features, aiming to help users easily switch and display content seamlessly on the front-end page.How does Anqi CMS help us build and manage multilingual websites and allow visitors to switch between different language versions smoothly?

2025-11-08

How to use the recommendation attribute (Flag) of AnQi CMS to display featured content on the homepage or special page?

AnQi CMS provides an efficient way to manage and highlight important content on your website, that is, through the "recommended attribute" (Flag).This feature allows you to easily display carefully selected content on the homepage, special pages, or other key positions, thereby guiding visitors' attention and enhancing the interactivity and information transmission efficiency of the website. ### Recommended Attribute Settings: The First Step of Content Selection In the AnQi CMS backend, the starting point of content management is to publish or edit documents.When you are ready with high-quality content, you hope it will stand out at a key position on the website

2025-11-08

How to customize the content model field and flexibly call it to display its content in the template?

AnQiCMS is one of the core strengths in content management, with its flexible and customizable content model.This allows us to no longer be limited by a fixed content structure, enabling us to create personalized content types that meet the actual operational needs of the website.No matter if you are publishing technical articles, showcasing product details, or managing event information, custom content model fields can help you accurately construct the content structure you need and ultimately flexibly display it on the website front end.

2025-11-08

How to set up an independent template for the single page of AnQi CMS to achieve highly personalized display?

In website operation, we often encounter such needs: some single pages, such as 'About Us', 'Contact Information', or 'Product Download' pages, need to have unique layouts and functions to provide a more unique user experience or carry specific marketing goals.AnQi CMS understands the importance of personalized display and therefore provides a very flexible way for us to tailor exclusive templates for each single page, achieving highly personalized display effects.

2025-11-08