How can AnQi CMS display a list of documents under a specified category and perform pagination?

Calendar 👁️ 71

AnQiCMS (AnQiCMS) with its flexible template mechanism and powerful content management features, makes the display of website content very simple and efficient.For many websites, clearly displaying content by category and providing convenient pagination navigation is the key to improving user experience and optimizing search engine rankings.Next, let's learn how to easily implement document list display and pagination functionality under specified categories in Anqi CMS.

Flexible configuration, control content display

The AnQi CMS template system uses syntax similar to the Django template engine, making content calls intuitive and powerful. To display a document list under a specified category and perform pagination, several core template tags are mainly used:archiveListUsed to obtain the document list data,categoryDetailUsed to obtain the details of the current category, as well,paginationUsed to generate pagination navigation. They work together to make the display and browsing of dynamic content easy.

Firstly, we need to find or create the corresponding category list template file in the current topic template folder. Usually, these files are located in/template/{你的模板名称}/{内容模型表名}/list.htmlFor example, if it is an article list, it might bearticle/list.html. If you want to set a unique layout for a specific category, you can also createlist-{分类ID}.htmlsuch naming format, for examplearticle/list-10.htmlThe system will automatically recognize and apply.

In the list page template, we first need to obtain some basic information about the current category, such as the category name and description, which is very important for the page's SEO and user understanding. You can usecategoryDetailLabel to complete this task:

{# 获取当前分类的详细信息,用于页面标题、描述等 #}
<h1 class="category-title">{% categoryDetail with name="Title" %}</h1>
<p class="category-description">{% categoryDetail with name="Description" %}</p>

This code will directly output the category title and description of the current page, no need to specify the ID, the system will automatically detect. If you need to get the category information of a specific ID, you can also do so byid="你的分类ID"parameter.

Dynamically retrieve document list

The core part is next——Retrieve document lists under specified categories. Anqicms providesarchiveListThe tag allows you to filter documents based on various conditions. To implement pagination, we need totypethe parameter to"page".

Assuming we want to display 10 articles per page on the category page, the template code can be written like this:

<div class="document-list">
    {# 使用 archiveList 标签获取指定分类下的文档列表,并开启分页功能 #}
    {# categoryId="0" 表示不指定分类ID,系统会自动获取当前页面的分类ID #}
    {# type="page" 开启分页,limit="10" 设置每页显示10条文档 #}
    {% archiveList archives with type="page" limit="10" %}
        {% for item in archives %}
        <article class="document-item">
            {# 检查文档是否有缩略图,并显示 #}
            {% if item.Thumb %}
            <a href="{{item.Link}}" class="document-thumb">
                <img src="{{item.Thumb}}" alt="{{item.Title}}">
            </a>
            {% endif %}
            <div class="document-info">
                <h2 class="document-title"><a href="{{item.Link}}">{{item.Title}}</a></h2>
                <p class="document-description">{{item.Description}}</p>
                <div class="document-meta">
                    {# 使用 stampToDate 格式化发布日期 #}
                    <span>发布日期: {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                    <span>浏览量: {{item.Views}}</span>
                </div>
            </div>
        </article>
        {% empty %}
        {# 如果当前分类下没有文档,显示提示信息 #}
        <p class="no-content">当前分类下暂无文档。</p>
        {% endfor %}
    {% endarchiveList %}
</div>

in thisarchiveListtags:

  • archivesIt is a variable name we define, which will contain the document list data obtained.
  • type="page"Tell the system that we need a pagination mode list, sopaginationthe tag can work properly.
  • limit="10"then specifies that 10 documents are displayed per page.
  • categoryId="0"Here is a tip, it means that we do not need to explicitly specify the category ID, the system will intelligently recognize the category according to the current page URL. Of course, you can also manually specify one or more category IDs if needed, for examplecategoryId="1,2,3".
  • {% for item in archives %}Loop through the document list,itemThe variable contains the details of each document, such asitem.Title(Title),item.Link(Link),item.Description(Summary),item.Thumb(thumbnail),item.CreatedTime(Publishing time) anditem.Views(Views) and so on.
  • {% empty %}IsforA practical feature of the loop, whenarchivesIf the list is empty, it will display{% empty %}and{% endfor %}between the content, to avoid page blank.
  • stampToDateThe filter is used to format timestamps into readable date strings,"2006-01-02"It is a special date formatting reference value in the Go language.

Build elegant pagination navigation

We need to provide users with convenient pagination navigation as well.paginationTags are the tools that enable this function, they will automatically generate links for 'Home', 'Previous Page', 'Next Page', and the middle page numbers.

Add the following code toarchiveListAfter the label, you can see the pagination navigation:

`twig

Related articles

How to display content from a specific site by using label parameters in a multi-site environment?

When using AnQiCMS for website management, the multi-site feature undoubtedly brings great convenience to users with multiple brands, sub-sites, or content branches.It allows us to efficiently manage multiple independent websites on a unified backend.However, in actual operation, we sometimes encounter a specific requirement: to display the content of another specific site on a site.For example, the main site wants to reference some of the latest articles from the child site, or a specific thematic site wants to display product information from another cooperative site.At this moment, 'How to set up an environment across multiple sites'

2025-11-08

How to troubleshoot when the AnQiCMS program is upgraded and the front-end page does not update?

How to troubleshoot when the front page does not update after the AnQiCMS program upgrade? When you eagerly upgraded the AnQiCMS program, expecting new features and optimizations to immediately appear on your website, only to find that the front page remained unchanged and stuck in the old version, that feeling is indeed quite crazy.Don't worry, this is usually not a big problem, mostly due to caching or program loading mechanisms.Today we will work together to investigate in detail and see how to make your website's front-end look brand new.

2025-11-08

How to implement content parameter filtering and dynamically adjust the list display results in AnQiCMS?

In a content management system, allowing users to quickly find the information they need according to their own needs is the key to enhancing the website experience and content value.AnQiCMS provides a powerful custom content model and flexible template tags, which helps us easily implement content parameter filtering, dynamically adjust the display results of the list, and greatly enhance the interaction and user-friendliness of the website content.This article will discuss in detail how to use these features in AnQiCMS, from backend configuration to frontend display, and step by step to implement content parameter filtering.

2025-11-08

How to accurately control the count and iteration order of list loops in the template?

In AnQi CMS, the content list is a core component of our website, whether it is an article list, product display, or other data modules, it cannot do without looping through data in the template and displaying it.Efficiently and accurately control the looping behavior of these lists, which not only makes the content presentation more flexible and diverse but also significantly improves the user experience and the overall performance of the website.The template engine of Anqi CMS has borrowed the syntax of Django, providing us with powerful list loop control capabilities.

2025-11-08

How to sort the document list of Anqi CMS by views or publish time?

How to effectively organize and present content in website construction and operation is the key to improving user experience and content discovery efficiency.For friends using AnQiCMS, it is very practical to flexibly sort the document list.Whether it is to make visitors see the most popular articles first or the latest updates, AnQiCMS provides a simple and powerful way to achieve this.

2025-11-08

How to filter document lists in AnQi CMS based on recommended attributes (such as headlines, recommendations)?

AnQi CMS as an efficient content management system, provides rich functions to help operators manage and display website content.Among the "recommended properties" feature is a very practical tool, which allows us to flexibly mark documents, thereby realizing dynamic filtering and display of specific content in different areas of the website.This article will discuss in detail how to use recommended attributes to filter document lists in AnQi CMS, making the website content more dynamic and attractive.

2025-11-08

How to exclude specific category content from the document list?

In website operation, we often need to flexibly control the display of content.For example, you may want to display the latest articles on the homepage, but not include a specific category such as "internal notices" or "archived content";Or in a product list, you want to exclude those categories that are "discontinued" or "internal testing", to keep the user interface simple and clear. A security CMS provides very convenient and powerful functions to meet such needs.By cleverly using the template tag `archiveList`

2025-11-08

How to achieve accurate display of in-site search results in Aiqi CMS?

The importance of on-site search functionality in daily website operation is self-evident.It is not only a bridge for users to quickly find the information they need, but also a key link to improve user experience, extend visit duration, and even promote conversion.If a user enters a keyword and gets a bunch of irrelevant results, they are likely to leave quickly.Therefore, how to achieve accurate display of in-site search results in AnQiCMS is a topic that every content operator should delve into.AnQiCMS is a system specially designed for content management, with a powerful and flexible search mechanism and content organization capabilities

2025-11-08