How to add pagination and optimize the display effect for document lists in AnQiCMS?

Calendar 👁️ 73

In website operations, how to efficiently display a large amount of content while ensuring smooth user experience is an issue that should not be overlooked.The pagination feature of the document list is the key to solving this problem.AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides intuitive and powerful template tags, allowing you to easily add pagination features to document lists and optimize the display on this basis, making your website content more attractive.

The core of AnQiCMS pagination:archiveListwithpaginationCollaboration of tags

In Anqi CMS, to implement pagination for document lists, it mainly relies on two core template tags:archiveList(Document list tag) andpagination(Pagination tag). They work together,archiveListResponsible for obtaining document data organized by pages, andpaginationthen generate clickable page navigation based on this data.

Step 1: Prepare the paginated document list

First, you need to go through the template in order toarchiveListLabel to retrieve document data. This label function is powerful, and it can filter and sort documents based on multiple conditions. The most critical thing to enable pagination is to settypethe parameter to"page".

For example, if you want to display a list of articles under a category and want it to be paginated with 10 items per page, you can write it like this:

{% archiveList archives with type="page" moduleId="1" categoryId="1" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <p>{{item.Description}}</p>
            <div>
                <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                <span>发布时间:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>阅读量:{{item.Views}}</span>
            </div>
        </a>
        {% if item.Thumb %}
        <a href="{{item.Link}}">
            <img alt="{{item.Title}}" src="{{item.Thumb}}">
        </a>
        {% endif %}
    </li>
    {% empty %}
    <li>
        当前分类下暂无文档。
    </li>
    {% endfor %}
{% endarchiveList %}

In the code above:

  • archivesIs the variable name you define for the document list data obtained.
  • type="page"Explicitly inform the system that this list needs pagination processing.
  • moduleId="1"Indicates retrieving the document of the article model (usually the ID of the article model is 1).
  • categoryId="1"Used to specify which category of documents to display.If you wish to automatically obtain based on the category of the current page you are visiting, you can omit this parameter or set its value to the ID of the current page category.
  • limit="10"sets the number of documents displayed per page to 10.

Whentypeis set to"page"after,archiveListthe tag returns the document list data (inarchivesIn the variable), it will also pass the pagination-related information to the system for subsequent processingpaginationlabel usage

Second step: Add pagination navigation

After the document data is organized by page, the next step is to usepaginationA tag to generate page navigation. This tag usually follows inarchiveListthe lower part of the tag because it depends onarchiveListthe pagination context information generated.

paginationLabels are automatically generated based on the current page, total page count, and other information, creating links for 'Home', 'Previous', 'Next', and page numbers in the middle.

<div class="pagination-container">
    {% pagination pages with show="5" %}
    <ul>
        <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">首页</a></li>
        {% if pages.PrevPage %}
            <li class="page-item"><a href="{{pages.PrevPage.Link}}">上一页</a></li>
        {% endif %}
        {% for item in pages.Pages %}
            <li class="page-item {% if item.IsCurrent %}active{% endif %}"><a href="{{item.Link}}">{{item.Name}}</a></li>
        {% endfor %}
        {% if pages.NextPage %}
            <li class="page-item"><a href="{{pages.NextPage.Link}}">下一页</a></li>
        {% endif %}
        <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{pages.LastPage.Link}}">尾页</a></li>
    </ul>
    <p>总共 {{pages.TotalItems}} 条文档,分为 {{pages.TotalPages}} 页,当前是第 {{pages.CurrentPage}} 页。</p>
    {% endpagination %}
</div>

In this example:

  • pagesIs the variable name you define for pagination information.
  • show="5"Controls the maximum number of middle page number links displayed. You can adjust this number according to your design requirements.
  • pagesVariable contains rich pagination data, for example:
    • pages.TotalItems: Total document count.
    • pages.TotalPages: Total number of pages.
    • pages.CurrentPage: Current page number.
    • pages.FirstPage/pages.PrevPage/pages.NextPage/pages.LastPageObjects representing home page, previous page, next page, and end page, each containingLink(link address) andIsCurrent(whether it is the current page) and other properties.
    • pages.PagesAn array that includes the page number objects displayed in the middle, each object also hasLinkandIsCurrentProperty.

You can flexibly build various styles of pagination navigation through these fields.

Optimize the display effect of the document list

Just implementing pagination is the first step. To truly attract users to the document list, it is necessary to refine its display effect.

  1. UtilizeitemDisplay of rich content variable archiveListTag looping initemVariables provide you with detailed information about the document, much more than just the title. You can display thumbnails, publication time, document description, reading volume, and category based on your needs. For example:

    • Title and Link:item.Titleanditem.LinkThe most basic, make sure that clicking the title can jump to the detail page.
    • Thumbnail:item.Thumboritem.LogoCan be used to display the picture of the list item, making the list more vivid.
    • Document Introduction:item.DescriptionProvided a brief overview of the article.
    • Read count:item.ViewsCan be used to display the popularity of the article.
  2. Formatted publish timeThe time field in AnQiCMS is typically stored in timestamp format. UsestampToDatetags to convert it to a human-readable date and time format, such as:{{stampToDate(item.CreatedTime, "2006年01月02日 15:04")}}

  3. content truncation to maintain cleanlinessIn order to avoid the list item content from being too long, you can use a filter to truncate the article description.truncatechars(Character truncation) andtruncatewords(Word truncation) are very practical choices:{{item.Description|truncatechars:100}}The description will be truncated to 100 characters and a ellipsis will be added at the end.

  4. CSS style beautificationAfter the HTML structure is built, it is crucial to use CSS to give the list and pagination a beautiful style.You can add different styles to list items, pagination links, the current page number, etc. to enhance the visual effects and user interaction experience.<li>Element additionactiveClass, then write the corresponding CSS rules to highlight it.

Comprehensive Optimization Example:

<div class="document-list">
    {% archiveList archives with type="page" moduleId="1" limit="10" %}
        {% for item in archives %}
        <div class="list-item">
            {% if item.Thumb %}
            <a href="{{item.Link}}" class="item-thumb">
                <img src="{{item.Thumb}}" alt="{{item.Title}}">
            </a>
            {% endif %}
            <div class="item-content">
                <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
                <p class="item-description">{{item.Description|truncatechars:150}}</p>
                <div class="item-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>
        </div>
        {% empty %}
        <p>抱歉,目前没有找到符合条件的文档。</p>
        {% endfor %}
    {% endarchiveList %}
</div>

<div class="pagination-nav">
    {% pagination pages with show="5" %}
    <ul class="pagination-list">
        <li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">首页</a></li>
        {% if pages.PrevPage %}
            <li><a href="{{pages.PrevPage.Link}}">上一页</a></li>
        {% endif %}
        {% for item in pages.Pages %}
            <li class="{% if item.IsCurrent %}active{% endif %}"><a href="{{item.Link}}">{{item.Name}}</a></li>
        {% endfor %}
        {% if pages.NextPage %}
            <li><a href="{{pages.NextPage.Link}}">下一页</a></li>
        {% endif %}
        <li class="{% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{pages.LastPage.Link}}">尾页</a></li>
    </ul>
    <p class="pagination-info">总计 {{pages.TotalItems}} 篇文章,当前显示第 {{pages.CurrentPage}} 页 / 共 {{pages.TotalPages}} 页。</p>
    {% endpagination %}
</div>

Actual Operation Suggestions and **Practice

  1. Template File Location: The list page template file is usually located according to your template organization mode,/template/{您的模板目录}/{模型表名}/list.html(Folder Organization Mode) or/template/{您的模板目录}/{模型表名}_list.html(Flattened organization mode). For example, the article list might betemplate/default/article/list.html.
  2. Dynamically obtain category IDIn the actual category list page,categoryIdParameters usually do not need to be manually specified with a specific ID, the system will automatically determine the current category based on the URL path. If you want to retrieve documents for all categories, you cancategoryIdis set to"0".
  3. Static rulesEnsure your website is properly configured with pseudo-static rules (via Background "Function Management" -> "Pseudo-static Rules"), so that the generated pagination URLs will be beautiful and有利于SEO的。
  4. DebugIn the process of development, use the browser developer tools to check the generated HTML structure and link for correctness.If the data is not displayed as expected, check that the tag parameters are correct, especially the case-sensitive parameter names.

Summary

By flexibly using the AnQiCMS providedarchiveListandpaginationThese core template tags, combined with various filters for detailed processing, allow you to easily implement efficient pagination for your website's document list and present it beautifully and practically according to your design needs.This highly customizable feature is exactly the powerful advantage that AnQiCMS shows in content management.


Frequently Asked Questions (FAQ)

  1. Why is the pagination navigation not displayed in my document list? What is the reason?
    • The most common reason is that you are in the `

Related articles

How to filter and display the document list of a specified category or model with the `archiveList` tag in AnQiCMS?

AnQiCMS as an efficient enterprise-level content management system, provides users with flexible and diverse content management and display capabilities.When building a website, we often need to display document lists based on specific conditions, such as only showing articles in a particular category, or only listing entries of specific content models (such as products, services).At this time, the `archiveList` tag has become a powerful tool in our hands.It is not only powerful but also very intuitive to use, making it easy for us to meet these needs.### `archiveList`

2025-11-07

How to use the `for` loop tag in AnQiCMS template to iterate and display content list?

In AnQiCMS, efficiently displaying content lists is a core requirement for website operation.Whether it is articles, products, categories, or custom data, we need a flexible mechanism to traverse and present this information.AnQiCMS's powerful template engine provides a `for` loop tag, which acts as a helpful assistant, making it easy for us to achieve this goal.

2025-11-07

How to use the `include` tag in AnQiCMS templates to implement modular display of common components (such as headers and footers)?

When building a website, we often encounter such situations: the header (Header), footer (Footer), and some sidebars, navigation menus, and other components almost appear on every page.If each time these common sections of the code are written repeatedly, not only does it take time and effort, but also once it needs to be modified, it has to be searched and updated on each page, which is inefficient and prone to errors.

2025-11-07

How to define the basic layout in AnQiCMS templates and use the `extends` tag to unify the display style?

When building a website, maintaining a unified page style and clear structure is crucial for improving user experience and development efficiency.AnQiCMS provides a powerful and flexible template engine, which draws on the excellent ideas of Django templates, especially the use of the `extends` tag, making this goal achievable. ### The Foundation of a Unified Style: Basic Layout Template Imagine that your website is like a meticulously designed building, where each room has unique decorations, but the load-bearing walls, roof, and foundation are unified.

2025-11-07

How to retrieve and display the complete content and properties of a single document using the `archiveDetail` tag?

When using AnQiCMS to build website content, displaying the complete information of a single document is one of the core requirements.No matter whether it is the detailed content of an article, a detailed introduction of a product, or any other specific entry of a custom content model, a highly efficient and flexible way is needed to extract and present this data.This is where the `archiveDetail` tag comes into play.

2025-11-07

How to display the link to the previous and next documents on the AnQiCMS document detail page?

In the ocean of website content, users often hope to browse related information smoothly, not wanting to return to the list to find the next article after reading a wonderful article.This not only affects user experience, but also benefits the internal link structure of the website and search engine optimization (SEO) a lot.AnQiCMS has fully considered this point, providing a convenient and quick navigation function for the content detail page, allowing users to easily navigate between different documents.The AnQiCMS template system is very flexible, it adopts the syntax of the Django template engine

2025-11-07

How does the `relatedArchive` tag display a list of related articles based on document relevance?

In the daily operation of a website, how to make users naturally discover more interesting content after reading an article is the key to improving user experience, extending the time spent on the website, and even optimizing SEO effects.AnQi CMS understands this and provides powerful template tag features, where the `relatedArchive` tag is exactly used to intelligently display related article lists.## `relatedArchive` label

2025-11-07

How does the AnQiCMS `categoryList` tag display hierarchical category structures and show category information?

In AnQi CMS, website categories are the foundation for organizing content. Whether it's articles, products, or other custom models, a clear category structure can greatly enhance user experience and the website's SEO effectiveness.The Anqi CMS provides a powerful `categoryList` tag, allowing us to flexibly display single or multi-level classification structures and easily obtain detailed information about each classification.### Master the basic usage of the `categoryList` tag To display the category list, we first need to use the `categoryList` tag

2025-11-07