How to add a unique `data-id` attribute to each page number button in AnQiCMS pagination?

Calendar 👁️ 77

As an old soldier in the field of website operation for many years, I know that every detail can affect the performance of the website, user experience, and even the depth of data analysis.AnQiCMS is a modern content management system developed based on the Go programming language, which provides strong support for our operational work with its high efficiency, flexibility, and ease of expansion.It has a unique Django template engine syntax that allows even relatively complex customization needs to be elegantly implemented through concise code.

Today, let's explore a very practical little trick in daily operations and data analysis: how to add unique buttons for each page number in the AnQiCMS pagination navigationdata-idProperties. This not only helps us track user behavior more accurately, but also brings more possibilities to front-end interaction.

Understand the pagination navigation tags of AnQiCMS.

In AnQiCMS, the pagination feature is supported by powerfulpaginationThe tag can be used to implement. This tag is very flexible, able to automatically generate a complete page navigation structure based on the content list of the current page, including home page, previous page, middle page numbers, next page, and end page.

paginationTags are usually witharchiveListortagDataListcontent list tags to work together, it receives apagesA variable that contains all the information needed for pagination. For example, we might call the pagination tag like this in the template:

<div class="pagination">
    {% pagination pages with show="5" %}
    <ul>
        <li>总数:{{pages.TotalItems}}条,总共:{{pages.TotalPages}}页,当前第{{pages.CurrentPage}}页</li>
        <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 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}}">{{pages.NextPage.Name}}</a></li>
        {% endif %}
        <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a></li>
    </ul>
    {% endpagination %}
</div>

In this structure,pages.Pagesis an array object that contains each page number displayed in the middle (usually a number), each page number itemitemhasName(page number),Link(Page link) andIsCurrent(Is the current page) and other properties. Our goal is to use this information to add a unique identifier to each page linkdata-idProperty.

Why do we need to add to the page buttondata-id?

At first glance, this may seem like a trivial change, but in actual website operations, it can bring many benefits:

  1. Precise data tracking and analysisThrough adding a uniquedata-idWe can configure event tracking more accurately. For example, when using Google Analytics, Baidu Statistics, or any other behavioral analysis tool, we can capture which specific page the user clicked on, such asdata-id="page-3") to navigate, rather than just knowing that a pagination button was clicked.This is crucial for analyzing user behavior patterns in deep content browsing, optimizing content organization and pagination strategies.

  2. Enhance front-end interaction and user experience: Front-end JavaScript can easily pass throughdata-idProperties to select and operate specific page number buttons. For example, when the user scrolls to the bottom of the page, we can according todata-idHighlight the adjacent page numbers of the current page, or add dynamic effects to specific page number buttons. This allows developers to build richer and smarter user interfaces.

  3. Improve maintainability and test convenienceDuring automated testing or debugging,data-idIt provides a stable and unique selector. Compared to relying on CSS class names or HTML structure,data-idIt is less likely to fail due to UI adjustments, thus simplifying the writing and maintenance of test scripts.

Practical: Adding pagination navigation for AnQiCMSdata-idproperty

To implement adding a unique attribute to each page number buttondata-idwe mainly need to modifypaginationthe loop inside the tagpages.Pagessection.

Let us find the part of the example code mentioned above that renders the middle page number list:

{% for item in pages.Pages %}
    <li class="page-item {% if item.IsCurrent %}active{% endif %}"><a href="{{item.Link}}">{{item.Name}}</a></li>
{% endfor %}

here,item.NameIt is the current page number, which is inherently a good unique identifier. We can use it directly asdata-idthe value.

We make the following modifications to the above code:

<div class="pagination">
    {% pagination pages with show="5" %}
    <ul>
        {# 首页按钮 #}
        <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
            <a href="{{pages.FirstPage.Link}}" data-id="page-{{pages.FirstPage.Name}}">{{pages.FirstPage.Name}}</a>
        </li>
        {# 上一页按钮 #}
        {% if pages.PrevPage %}
            <li class="page-item">
                <a href="{{pages.PrevPage.Link}}" data-id="page-prev">{{pages.PrevPage.Name}}</a>
            </li>
        {% endif %}
        {# 中间页码按钮 #}
        {% for item in pages.Pages %}
            <li class="page-item {% if item.IsCurrent %}active{% endif %}">
                <a href="{{item.Link}}" data-id="page-{{item.Name}}">{{item.Name}}</a>
            </li>
        {% endfor %}
        {# 下一页按钮 #}
        {% if pages.NextPage %}
            <li class="page-item">
                <a href="{{pages.NextPage.Link}}" data-id="page-next">{{pages.NextPage.Name}}</a>
            </li>
        {% endif %}
        {# 尾页按钮 #}
        <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
            <a href="{{pages.LastPage.Link}}" data-id="page-{{pages.LastPage.Name}}">{{pages.LastPage.Name}}</a>
        </li>
    </ul>
    {% endpagination %}
</div>

Please note that in addition to the middle page number, we also added首页/上一页/下一页and尾页the button as welldata-id. For the page numbers, we useddata-id="page-{{item.Name}}"the format, which makes each page number'sdata-idEach is unique, for example, "page-1", "page-2", "page-3", etc. For special function buttons such as "Previous page" and "Next page", we have assigned more descriptive ones.data-id="page-prev"anddata-id="page-next"While the first page and last page are directly identified by their page numbers.

Deployment and verification

After completing the modification of the template code, the next step is to deploy it to your AnQiCMS website.

  1. Confirm the location of the template file: Typically, pagination navigation code exists in your template files, such as the article list page'slist.html, category page'scategory.html, or a dedicated partial template file for pagination (such aspartial/pagination.htmlYou need to find the one currently in use on your website, includingpaginationthe template file for the tags.
  2. **Modify

Related articles

How does AnQiCMS pagination tag handle invalid page number requests (such as page numbers out of range)?

As an experienced website operations expert, I am well aware that the core value of a content management system (CMS) lies not only in content publishing, but also in its careful consideration of user experience and search engine optimization (SEO).AnQiCMS is an enterprise-level content management system developed based on the Go language, with its efficient, secure, and SEO-friendly design philosophy, it always shows its unique and comprehensive consideration when dealing with some seemingly trivial but actually crucial functions.

2025-11-07

When there are multiple filter conditions, can the `pagination` tag correctly pass all parameters to the next page link?

## The Wisdom of Anqi CMS Pagination Tags: Deep Analysis of Parameter Auto-Transmission under Multi-Condition Filtering In modern website content management, users often need to filter content through multiple conditions to quickly locate the desired information.For example, on an e-commerce website, users may filter products at the same time such as 'T-shirt', 'red', and 'M size';On an article publishing platform, users may filter articles that are 'technical', 'Go language', and 'published in 2023'.After these filtering conditions take effect, users often need to browse more results through the pagination feature. At this time

2025-11-07

How to add image icons instead of text for the links of home, last page, previous page, and next page in pagination tags?

## An enterprise CMS pagination navigation is refreshed: goodbye text, embrace personalized image icons As a senior website operator, we know that every detail of user experience is crucial.A straightforward and aesthetically pleasing navigation system can greatly enhance the browsing comfort of users on the website.In AnQiCMS, pagination tags are the core components of the content list page, which are presented by default in text forms such as 'First Page', 'Last Page', 'Previous Page', 'Next Page', and so on.

2025-11-07

Is the HTML output structure of AnQiCMS's pagination tag fixed? Can the content of the page number's `<a/>` tag be fully customized?

As an experienced website operations expert, I fully understand the core status of the content management system (CMS) in website construction and daily operations.Especially for basic functions like pagination, flexibility is often directly related to user experience, search engine optimization (SEO), and the aesthetic beauty of front-end design.Many developers and operators are concerned about how much freedom a system like AnQiCMS, which pursues efficiency and customization, provides in the HTML output structure of pagination tags?

2025-11-07

`archiveList type="page"` combined with `pagination`, how will pagination adapt when the `limit` value changes?

As an experienced website operations expert, I know that it is crucial to be able to display content flexibly and efficiently in a content management system.AnQiCMS (AnQiCMS) offers great convenience for content operation with its excellent flexibility and powerful template tag system.

2025-11-07

Does AnQiCMS pagination tag support AJAX content loading to reduce overall page refresh?

As an experienced website operations expert, I fully understand how important page loading speed and interactive smoothness are in the pursuit of excellent user experience today.Especially in the scenario of handling pagination of a large amount of content, the traditional full-page refresh method often interrupts the continuity of the user's reading, even affecting retention.Therefore, does the AnQiCMS pagination tag support AJAX content loading to reduce the overall page refresh?This question naturally becomes a focus for many operators and developers.

2025-11-07

How can the `pagination` tag call data for a specific site using the `siteId` parameter in a multi-site management environment?

## Unlock AnQiCMS Multi-site Data: Deep Analysis of `pagination` Tag and `siteId` Parameter As an experienced website operations expert, I know that in a multi-site management environment, how to accurately and efficiently call and display data is one of the keys to operational success.AnQiCMS with its flexible multi-site management capabilities provides us with a strong foundation for content operations.Today, let's delve deeply into a problem that often arises in multi-site scenarios: how the `pagination` tag uses the `siteId` parameter

2025-11-07

How to apply different `show` parameters in the AnQiCMS template for different pagination types (articles, products, tags)?

In AnQiCMS template development, implementing pagination with different display parameters for different content types (such as articles, products, tags) is an important aspect for enhancing user experience and website professionalism.As an experienced website operation expert, I know that fine-grained content display can effectively guide users. Today, we will delve into how to巧妙运用`pagination`标签的`show`参数 in AnQiCMS to achieve this goal.

2025-11-07