How to flexibly control the display quantity and style of pagination page numbers with the `pagination` tag of AnQiCMS?

Calendar 👁️ 74

When managing a content-rich website, an efficient page navigation system is crucial for enhancing user experience and search engine optimization (SEO). AnQi CMS understands this and has built-in thepaginationTags provide fine-grained control, making the page number display on the website flexible and beautiful. This article will introduce you to how to use it in depthpaginationLabel, flexibly control the display quantity and style of pagination page numbers.

UnderstandpaginationThe core role of tags

In AnQi CMS,paginationThe label does not exist independently, it is usually used with content list labels such asarchiveList/tagDataList/commentListetc.) used together. When these list labelstypethe parameter to"page"They will return a paginated dataset instead,paginationThe task of the label is to generate the corresponding page navigation based on this dataset.

In simple terms,paginationThe tag is used to present the pagination logic calculated on the backend in a customizable HTML structure on the front-end, allowing us to easily implement 'Previous page', 'Next page', 'Home', 'End', and a series of page number navigation.

How to usepaginationTag

paginationThe basic usage of tags is very intuitive, it needs to be wrapped around{% pagination ... %}and{% endpagination %}Between. When using it, you need to pass the pagination data obtained through the list tag to it, usually we name this variable.pages.

For example, we might use it like this on a document list pagearchiveListandpagination:

{# 首先,通过 archiveList 获取分页数据 #}
{% archiveList archives with type="page" limit="10" %}
    {# 循环显示文档列表内容 #}
    {% for item in archives %}
        <li><a href="{{item.Link}}">{{item.Title}}</a></li>
    {% empty %}
        <li>暂无文档</li>
    {% endfor %}
{% endarchiveList %}

{# 接下来,使用 pagination 标签生成页码导航 #}
<div class="pagination-area">
    {% pagination pages with show="5" %}
        {# 这里是分页页码的具体显示内容,稍后详细说明 #}
    {% endpagination %}
</div>

Here, pagesThis variable contains all information related to pagination, such as total number of items, total number of pages, current page number, home link, previous page link, next page link, end page link, and most importantly—the array of middle page numbers.

Flexibly control the number of pages displayed:showParameter

paginationOne of the highlights of the tag is that it allows us to go throughshowParameters, flexibly control the display quantity of the middle page number area. This is very important to maintain the simplicity and beauty of page navigation.

showThe parameter accepts an integer value that determines how many page number links are displayed around the current page. For example:

  • show="3"This makes page navigation more compact, usually showing 1-2 page numbers before and after the current page, and the ellipsis appears earlier.
  • show="5"This is a commonly used setting that displays 2-3 page numbers before and after the current page, providing a good context without being too long.
  • show="7"If your page space is ample, or you want users to see more page number options, you can increase this value appropriately.

Reasonably setshowParameters that can keep pagination in good visual balance across different page counts and device sizes. For example, when the total number of pages is not many,showThe parameters will automatically adjust to display all page numbers without ellipses. When the total number of pages is very large, it can also intelligently hide some page numbers to avoid the page number bar being too long.

Custom pagination style and layout

paginationThe tag itself does not directly output styled HTML, it provides the data needed to build pagination.This means we can fully master the HTML structure and CSS style of pagination, achieving a highly customized appearance.

pagesMultiple properties are provided in the variable, for us to build styles:

  • pages.TotalItemsTotal number of content items.
  • pages.TotalPages: Total number of pages.
  • pages.CurrentPage: Current page number.
  • pages.FirstPage/pages.LastPage/pages.PrevPage/pages.NextPageThese are four special objects, each containingName(such as "Home") andLink(link address), as well asIsCurrent(whether the current page, usually the home page and the end page are not the current page).
  • pages.PagesThis is an array that contains page number objects in the middle part. Each object also hasName(page number),Link(link address) andIsCurrent(whether it is the current page).

By using these properties, we can easily construct various styles of pagination:

<div class="pagination-wrapper">
    <ul class="pagination-list">
        {# 显示总页数和当前页信息,可选 #}
        <li class="page-info">
            总{{pages.TotalPages}}页,当前第{{pages.CurrentPage}}页
        </li>

        {# 首页链接 #}
        <li class="page-item {% if pages.FirstPage.IsCurrent %}is-current{% 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 item in pages.Pages %}
        <li class="page-item {% if item.IsCurrent %}is-current{% endif %}">
            <a href="{{item.Link}}">{{item.Name}}</a>
        </li>
        {% endfor %}

        {# 下一页链接 #}
        {% if pages.NextPage %}
        <li class="page-item">
            <a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
        </li>
        {% endif %}

        {# 尾页链接 #}
        <li class="page-item {% if pages.LastPage.IsCurrent %}is-current{% endif %}">
            <a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
        </li>
    </ul>
</div>

In the above code, we added to each page item:page-itemclass, and make use of{% if item.IsCurrent %}or{% if pages.FirstPage.IsCurrent %}Determine if the current page is active, and addis-currentthe class. This way, we can control the style ofis-currentthe class to highlight the current page number, for example:

.pagination-list {
    display: flex;
    list-style: none;
    padding: 0;
    justify-content: center;
    align-items: center;
}

.page-item {
    margin: 0 5px;
}

.page-item a {
    display: block;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-decoration: none;
    color: #333;
    transition: background-color 0.3s ease;
}

.page-item a:hover {
    background-color: #f5f5f5;
}

.page-item.is-current a {
    background-color: #007bff;
    color: #fff;
    border-color: #007bff;
    pointer-events: none; /* 当前页不可点击 */
}

.page-info {
    margin-right: 15px;
    color: #666;
}

In this way, the layout, color, font, border, and all other visual elements of the page number can be adjusted according to the overall design style of the website, without being limited by the fixed styles provided by the CMS.

Complete example: Applying pagination on the document list page

Let's see a more complete example of how to implement pagination on the article list page:

`twig {# Assume this is the article list page template (e.g., archive/list.html) #} u003c!

<meta charset="UTF-8">
<title>{% tdk with name="Title" siteName=true %}</

Related articles

How to automatically generate the breadcrumb navigation of the page in the AnQiCMS template using the `breadcrumb` tag?

When browsing websites, we often notice a path information string at the top or bottom of the page, which clearly indicates our current location, such as "Home > Category > Article Title."}This is what we commonly refer to as Breadcrumb Navigation.It not only helps users better understand the website structure and improve the browsing experience, but also has a significant value for search engine optimization (SEO).Why is breadcrumb navigation important? For users, breadcrumb navigation is like a mini-map.

2025-11-08

How to use the `archiveFilters` tag in AnQiCMS to achieve combined filtering of document parameters?

## Mastering AnQiCMS: The Art of Using `archiveFilters` Tag for Document Parameter Combination Filtering It is crucial to provide users with accurate and efficient content search experience in content operation.Imagine if your website has a rich variety of content, but users find it difficult to quickly find the information they need. This will undoubtedly greatly affect user experience and the conversion rate of the website.

2025-11-08

How to enable and use the captcha feature of the留言表单in AnQiCMS?

The website guestbook is a good place to interact with visitors, which brings the website closer to the users.However, without proper protection, the message board will soon be overwhelmed by various spam, malicious submissions, and even automated scripts, which not only affects the cleanliness of the website but may also consume server resources and even damage the reputation of the website.Fortunately, AnQiCMS provides a simple and effective solution: the captcha feature.

2025-11-08

How to display comment content and user status for the `commentList` label in AnQiCMS?

Build a highly interactive website in AnQiCMS, the comment function is undoubtedly the key to increasing user engagement.The `commentList` tag is a great tool provided by AnQiCMS for this purpose, it can help website developers and operators flexibly display comment content, and clearly present the status of commenters, allowing visitors to grasp the dynamics of the comment area at a glance.### Core Feature Overview: Basic Usage of `commentList` Tag The `commentList` tag is mainly used to retrieve the comment list of a specified document

2025-11-08

How to format timestamp output to date or time string in AnQiCMS template?

In website operation, the date and time information of content publication, update, and other aspects are crucial for user experience and content management.AnQiCMS as a rich-featured content management system, provides flexible template tags, allowing users to easily format the timestamp data stored in the background into various easily readable date or time strings to meet different display requirements.

2025-11-08

How do the `urlize` and `urlizetrunc` filters handle URL links in the AnQiCMS template?

In website operation, we often need to embed various links in the content, whether they point to internal resources or external references.Manually converting plain text links into clickable hyperlinks is not only inefficient but also prone to errors.It is more important that standardized link handling is crucial for search engine optimization (SEO) and user experience.

2025-11-08

How to use the `length` filter to get the length of a string, array, or key-value pair in AnQiCMS templates?

In AnQiCMS template development, we often need to process and judge the data displayed on the page.Among them, getting the length of a string, array, or key-value pair is a very basic and practical operation.The AnQiCMS template engine provides the `length` filter, making this task simple and intuitive. ### Understanding the `length` filter: A tool for getting data length The `length` filter, as the name implies, is used to get the 'length' of the data.

2025-11-08

What search engines does the "Link Push" feature of AnQiCMS backend support for active push?

Today, with the rapid growth of internet content, the quick inclusion of website content is an important factor in increasing website traffic and influence.For many content operators and enterprises, how to make search engines discover and index new content on their websites in a timely manner is a core issue in SEO work.AnQiCMS (AnQi CMS) deeply understands this need, especially in the backend, integrating a convenient and powerful "link push" function, aimed at helping users deliver their carefully crafted content to major search engines in the shortest possible time, effectively shortening the cycle from content publication to indexing.###

2025-11-08