How to filter and loop through the document list under a specific category based on the category ID?

Calendar 👁️ 55

It is crucial to organize and present content when building and operating a website.Especially when website content becomes increasingly rich, how to allow visitors to quickly find the information they are interested in and clearly browse all articles under a specific topic has become a problem that requires careful design.AnQiCMS provides powerful and flexible content management capabilities, allowing us to easily achieve precise control and display of document lists.Today, let's discuss a common requirement: how to filter and loop through the document list under a specific category ID.This will help you better organize the website structure, improve user experience, and optimize the search efficiency of content.

Core function analysis:archiveListTag

In AnQiCMS, the core is to implement filtering and outputting document lists according to category ID, usingarchiveListThis template tag. It is like a powerful search tool that can accurately fetch the required documents from your content library.

archiveListTags have multiple parameters that can help you accurately locate content, the one most closely related to category filtering iscategoryId.

  • Specify a single category IDWhen you want to display all documents under a specific category (such as "Company News" or "Product Introduction"), you can directly assign the category's ID tocategoryIdParameter. For example, if the category ID of "Company News" is1, you can use it like this:{% archiveList archives with categoryId="1" %}.

  • Specify multiple category IDs: If you need to display documents from multiple discontinuous categories at the same time,categoryIdParameters are also supported. You only need to separate multiple category IDs with English commas,and it will be separated. For example,{% archiveList archives with categoryId="1,5,8" %}The output will be the category ID of1/5and8documents.

  • Control the number and type of display:archiveListtags also allow you to refine the definition of “relevant” throughlimitParameters control how many documents are displayed at once, for examplelimit="10"It means displaying 10 documents.typeThe parameter determines the type of the list,type="list"Used for regular lists,type="page"It means you plan to use the pagination feature.

  • Include or exclude subcategory documentsIn some cases, a large category may contain multiple subcategories.childThe parameter can help you decide whether to include the documents of subcategories in the current list. By default,childIstrueIt will include documents with subcategories. If you only want to display documents directly associated with the current category, you can set it tochild=false.

Practical operation: Filter and loop through the document list

UnderstoodarchiveListAfter the key parameters of the tag, let's see how to apply it in the actual template to display your content.

Scenario one: Output the latest documents under a specific category.

Suppose you want to display the latest documents under the "Company News" category on the homepage or a specific thematic page. First, you need to know the category ID of "Company News" (assuming it is1)。Then,you can usearchiveListtags to retrieve these documents and combineforloop tags to output them one by one.

{# 假设“公司新闻”的分类ID是 1 #}
<div class="news-list">
    <h3>公司新闻</h3>
    {% archiveList newsItems with categoryId="1" type="list" limit="5" order="id desc" %}
        {% for item in newsItems %}
        <article>
            <h4><a href="{{item.Link}}">{{item.Title}}</a></h4>
            <p>{{item.Description}}</p>
            <time>{{stampToDate(item.CreatedTime, "2006-01-02")}}</time>
        </article>
        {% empty %}
        <p>目前没有公司新闻发布。</p>
        {% endfor %}
    {% endarchiveList %}
</div>

In this code block:

  • `archiveList newsItems with category

Related articles

How to display the latest N articles or products on the homepage and implement pagination control?

## Asecurity CMS: The Practice of Efficiently Displaying the Latest Content on the Homepage and Implementing Pagination The homepage is an important entry point for visitors to understand the site content and obtain the latest information, it is crucial to clearly and effectively display the latest published articles or products.The AnQi CMS provides powerful and flexible template tags, which help us easily achieve this goal, and can also fine-tune content pagination to ensure a smooth user experience.

2025-11-08

How to output variables in a template and safely escape content to prevent XSS attacks?

In the process of managing and displaying website content, ensuring the security of user data is a crucial link.It is an issue that every website operator needs to pay attention to when the website needs to display user submitted content or data obtained from external sources, how to effectively prevent cross-site scripting (XSS) attacks.AnQiCMS (AnQiCMS) took this into full consideration from the very beginning, providing solid security guarantees for content output through its powerful template engine and flexible filter mechanism.### Cross-Site Scripting Attack

2025-11-08

How to output the current date and time in the AnQiCMS template and specify the format?

Displaying the date and time in the AnQiCMS template in a specific format is a common requirement in website content operations.Whether it is to display the publication time of articles, the deadline of events, or show the current year in the footer, accurate and beautiful time information can enhance the user experience.AnQiCMS provides simple and efficient template tags, allowing you to easily implement these features. Next, we will discuss in detail how to output the current date and time in the AnQiCMS template and specify the format you need.

2025-11-08

What role does the `extends` tag play in the AnQiCMS template inheritance system?

In AnQiCMS template development, the `extends` tag plays a core role, it is the key to building efficient, maintainable and structurally unified website templates.The `extends` tag can be understood as creating a bridge between 'master' and 'child pages', allowing you to easily define a common layout skeleton for the entire website without repeating a lot of the same code on each page.

2025-11-08

How to exclude specific categories or multiple categories of articles from the document list?

When managing website content in Anqi CMS, we often need to precisely control the display of articles.Sometimes, we may want certain category articles not to appear in the regular article list, such as for internal notifications, test content, or some promotional information that is only displayed on specific pages.AnQi CMS provides a simple and efficient method to meet this kind of need, allowing you to flexibly exclude articles of specific categories or multiple categories, thereby achieving more accurate content presentation.

2025-11-08

How to display articles under a specific category without including its subcategories?

In website content management, we often encounter such needs: we want to display articles under a specific category on a page, but we don't want to include the sub-category articles under that category to maintain the purity and focus of the content.For example, you may have a "Company News" category that includes subcategories such as "Enterprise Dynamics" and "Industry Information", but on the homepage, you only want to display the pure "Company News" without mixing in the content of all subcategories.

2025-11-08

How to filter and display a list of articles based on their recommended attributes (such as “Top Article”, “Recommended”)?

In Anqi CMS, efficient content management is one of the keys to website success.Article recommendation attribute, as an important link in the operation of content refinement, it can help us display website content more flexibly, guide users to pay attention to key information, and thus improve the activity and conversion rate of the website.This article will delve into how to filter and display article lists based on the recommended attributes of articles (such as "Headline

2025-11-08

How to display the article list according to the article views, publish time, or backend custom sorting?

In website operation, the way articles are displayed directly affects user experience and content access efficiency.A well-organized list of articles that can highlight key points, significantly improving user retention and information acquisition efficiency.AnQiCMS as a flexible content management system provides powerful article list display functions, not only can it flexibly filter content, but also can freely adjust the sorting method of articles according to your content strategy, making your website content more attractive.

2025-11-08