How to implement the document list page of AnQi CMS to filter and display pages according to the specified category ID?

Calendar 👁️ 52

In Anqi CMS, it is crucial to manage and display a large amount of content, especially when it is necessary to organize it by specific categories and display it with pagination.The AnQi CMS, with its flexible template engine, allows content operators to easily meet these requirements, providing users with a clear and efficient browsing experience.

Why is it necessary to filter and display pages by category?

Imagine a website with hundreds or even thousands of documents. If all the content is piled onto one page, users will feel overwhelmed and the website loading speed will be affected.By filtering by category, we can help users quickly locate the content areas they are interested in; pagination can effectively control the amount of content on a single page, improve loading speed, and guide users to browse more content step by step.This not only optimizes the user experience, but also greatly benefits search engine optimization (SEO), helping to improve the crawling efficiency and weight distribution of the website.

Core tags and mechanisms of AnQi CMS

The AnQi CMS template system has adopted the syntax of the Django template engine, using{{变量}}to output data,{% 标签 %}Performing logical control. The following core tags are mainly used for filtering and pagination of document lists:

  1. archiveListTagThis is the core tag for getting the document list.It allows us to filter documents based on various conditions (such as category ID, model ID, recommendation attributes, etc.) and set the type of the returned list (whether it is a normal list or a list prepared for pagination).
  2. paginationTag: Used specifically to generate pagination navigation tags. It will be based onarchiveListLabel-generated pagination data, constructing "Previous page
  3. categoryDetailTagThis tag helps us get the properties of the specified or current category when it is necessary to display detailed information such as category names, links, etc.

Understand the functions and usage of these tags, which is the foundation for building flexible document list pages.

Practice: Filter and paginate the document list according to the specified category ID.

Next, we will demonstrate how to implement filtering and pagination of document lists based on a specified category ID through specific steps and code examples.

Step 1: Determine the location of the template file

Firstly, you need to specify which template file your document list page will use. According to the template conventions of Anqi CMS (refer todesign-director.md), the template file for the document list page is usually located at:

  • {模型table}/list.htmlThis is the universal list page under the model category.
  • {模型table}/list-{文档分类ID}.htmlThis is a customized list page for a specific category.

For example, if you want to create a list page for the article model (assuming the model table isarticleBelow ID is10Create a dedicated list page for the category, you cantemplate/default/article/Create a file namedlist-10.htmlfile. If you just want to create a universal list page for all articles, then uselist.html. For the sake of universality of the example, we assume that it is inarticle/list.htmloperating.

Second step: usearchiveListLabel to get document list

In your list template file, usearchiveListtags to get the documents that need to be displayed. Here are some key parameters:

  • type="page":This is the key instruction to implement pagination display.It tells AnQi CMS not only to return document data but also to prepare all the necessary information for pagination.
  • categoryId="X": Used to specify the category ID you want to filter. For example,categoryId="10"Only documents under the category with ID 10 will be displayed. If you want to dynamically obtain the current category ID on the current category page (for example, by clicking on the navigation entry category list page), it is usually not necessary to set it explicitlycategoryId,archiveListAttempts to automatically read the category ID of the current page. If you need to specify manually or obtain it from elsewhere, for example, when looping through categories, you can set it tocategoryId=item.Id.
  • moduleId="Y"Make sure we are getting the correct document under the content model. For example, the article model.moduleIdIt is usually1, the product model could be2You can view the specific ID through the "Content Model" management interface on the back end.
  • limit="10"Set the number of documents to display per page.
{% archiveList archives with type="page" categoryId="10" moduleId="1" limit="10" %}
    {# 文档列表内容将在这里循环展示 #}
{% endarchiveList %}

In the above code,archivesis a variable that contains the document array filtered by specified conditions.

Third step: Loop to display the document content.

obtaining toarchivesAfter the array, you need to useforTo loop through and display the details of each document.

Inside the loop,itemThe variable represents the current document object, you can accessitem.Title/item.Link/item.Descriptionproperties to get various data of the document.

{% archiveList archives with type="page" categoryId="10" moduleId="1" limit="10" %}
    {% for item in archives %}
        <div class="document-item">
            <a href="{{item.Link}}">
                <h3 class="document-title">{{item.Title}}</h3>
                {% if item.Thumb %}<img src="{{item.Thumb}}" alt="{{item.Title}}" class="document-thumb">{% endif %}
                <p class="document-description">{{item.Description}}</p>
            </a>
            <div class="document-meta">
                {# 获取文档所属分类的名称和链接 #}
                <span>分类:<a href="{% categoryDetail with name='Link' id=item.CategoryId %}">{% categoryDetail with name='Title' id=item.CategoryId %}</a></span>
                <span>发布时间:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>浏览量:{{item.Views}}</span>
            </div>
        </div>
    {% empty %}
        <p class="no-content-message">当前分类下暂无文档。</p>
    {% endfor %}
{% endarchiveList %}

Please note{% empty %}a block whenarchivesWhen the list is empty, it will display a custom no-content message instead of a blank space.stampToDateThe filter is used to format timestamps into readable dates.

Step four: Integrate page navigation (pagination)

InarchiveListlabel'sendarchiveListAfter that, usepaginationtags to generate pagination navigation.paginationTags will automatically associate with the nearesttype="page"ofarchiveListGenerated pagination data.

paginationCommon parameters for tags areshowIt determines how many page number numbers are displayed in the page navigation.

”`twig {% archiveList archives with type=“page” categoryId=“10” moduleId=“1” limit=“10” %}

{# 文档列表内容如上所示 #}
{% for item in archives %}
    <div class="document-item">
        {# ... 文档内容 ... #}
    </div>
{% empty %}
    <p class="no-content-message">当前分类下暂无文档。</p>
{% endfor %}

{% endarchiveList %}

{% pagination pages with show="5" %}
    <ul class="pagination-list">
        {# 首页链接 #}
        <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
            <a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
        </li>
        {# 上一页链接 #}
        {% if pages.PrevPage %}
        <li class="page-item">
            <a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
        </li>
        {% endif %}
        {# 中间页码链接 #}
        {% for page_item in pages.Pages %}
        <li class="page-item {% if page_item.IsCurrent %}active{% endif %}">
            <a href="{{page_item.Link}}">{{page_item.Name}}</a>
        </li>
        {% endfor %}
        {# 下

Related articles

How to set up a static URL structure for the article detail page in Anqi CMS to optimize SEO?

In website operation, a clean and readable URL structure is crucial for search engine optimization (SEO).A pseudo-static URL, as the name implies, refers to those URLs that look like static HTML pages but are actually generated by backend dynamic programs.This URL can preserve the flexibility of dynamic content management, provide a friendly crawling path for search engines, and also improve the user experience, making it easier for them to understand the page content.

2025-11-08

How to configure multilingual content switching in AnQiCMS to support browsing by users from different countries?

Today, with the deepening of globalization, it is a crucial step to allow your website to support multiple languages and reach users in different countries, expanding the market and enhancing brand influence.AnQiCMS (AnQi CMS) fully considered this requirement at the initial design, providing users with an efficient and flexible multilingual content switching solution.AnQiCMS is at the core of implementing multilingual content switching, with its powerful **multi-site management** function, supplemented by **default language package** configuration, and the flexible application of **front-end template tags**

2025-11-08

How to use AnQi CMS to customize article model fields for personalized content display?

In Anqi CMS, the flexibility of the content model is one of its core advantages. It not only helps us manage traditional articles and product information, but also allows us to create highly personalized content types according to actual business needs.And customizing the article model field is the key step to achieving this personalized display.The essence of content operation is to provide users with the information they truly need, and present it in the most intuitive and attractive way.Imagine if your website needs to display movie reviews, you may also need to show 'director', 'lead actors', and 'release date'

2025-11-08

How to use the AnQiCMS content model feature to customize

In AnQiCMS, the content model feature is one of its core highlights, it gives the website great flexibility, allowing you to break free from the constraints of traditional CMS fixed content types, and customize exclusive content structures according to your business needs.Imagine if your website is not just for publishing articles or products, but also needs to display real estate information, job openings, event details, and even recipes. If you use a fixed 'article' type, these pieces of information will be difficult to organize and manage.And the content model is the powerful tool to solve this pain point.### Understand the content model: the "skeleton" of website content In simple terms

2025-11-08

How does AnQiCMS ensure that website content is displayed efficiently under high concurrency requests?

Under high traffic access, the smooth display of website content is a core issue that every operator is extremely concerned about.How to ensure that the content is presented quickly and stably in front of users when a large number of users flood into the website at the same time, this not only tests the carrying capacity of the website server, but also deeply depends on the underlying architecture and optimization strategy of the content management system.AnQiCMS (AnQiCMS) was designed with 'high concurrency' as one of its core advantages, providing a solid guarantee for the efficient display of content under high concurrency requests through a series of technical highlights and operational support.

2025-11-08

How to achieve unified management and independent front-end display of multi-site content in AnQi CMS?

In AnQiCMS, efficiently managing content for multiple websites and ensuring each website has an independent frontend display is a core concern for many enterprises and content operators.AnQiCMS is a CMS designed specifically for multi-site management, providing a comprehensive solution that makes this process intuitive and easy to operate. ### Core Advantages of AnQiCMS Multi-Site Management The multi-site management function of AnQiCMS does not simply copy multiple copies of the program, but supports multiple independently operated websites through a core system.This architecture brings significant advantages

2025-11-08

How to utilize the flexible content model of AnQiCMS to customize and present different types of content structures?

In today's content-driven digital world, websites are no longer just collections of static information, but they carry various forms of content from in-depth articles, beautiful products, limited-time activities to customer cases.Each content type has its unique information structure and display requirements.However, traditional website content management systems are often limited to preset 'article' or 'page' modes, making it difficult to meet the growing demand for personalized content management.

2025-11-08

How does AnQiCMS implement multilingual support to seamlessly display website content for users of different languages?

In today's global internet environment, website content can be presented in multiple languages, which is crucial for expanding the market and enhancing user experience.AnQiCMS is proficient in this, providing strong multilingual support capabilities for website operators to ensure that users of different languages can browse website content seamlessly. ### Backend Settings and System Language Environment To achieve seamless display of multilingual content, the first step is to start from the Anqicms backend configuration.The system provides an option for a "default language package", where you can choose Chinese, English, and other built-in languages in the global settings

2025-11-08