How to get and display the current page number in AnQiCMS template?

Calendar 👁️ 65

Navigate the beauty of pagination: Easily obtain the current page number in AnQiCMS templates

As an experienced website operations expert, I know that an efficient content management system is crucial for the vitality of a website.AnQiCMS with its high-performance architecture based on the Go language and flexible template mechanism has become the preferred choice for many small and medium-sized enterprises and content operation teams.In daily operations, we often need to display pagination information in scenarios such as list pages, search result pages, etc., among which obtaining and displaying the current page number is a basic and core requirement.Today, let's delve deeply into how to elegantly obtain and display the current page number in the AnQiCMS templatepages.CurrentPage.

Understand the pagination mechanism of AnQiCMS

In AnQiCMS, pagination is not just a simple list of numbers, it is a highly optimized feature closely integrated with the content list. Whether it is an article list (through thearchiveListLabel), product list, or document list under the label (throughtagDataListLabel), when we need to implement pagination display, the key is to display these list labelstypethe parameter to"page"Once specified as"page", AnQiCMS will prepare a complete set of page context data for you in the background, which can be called by the front-end template.

This page context data is throughpaginationThe tag appears in front of your template.paginationThe tag is designed specifically for handling pagination logic in AnQiCMS, it can not only generate pagination links but also provide detailed information such as total pages, total entries, first page, last page, previous page, next page, and current page number.

The core of getting the current page number:pages.CurrentPage

When you introduce and use the AnQiCMS templatepaginationWhen tagging, for example:

{% pagination pages with show="5" %}
    {# 在这里,'pages' 就是包含所有分页信息的对象 #}
{% endpagination %}

The system will create a namedpages(or you can use a custom variable name, here is the example of using the variable name)pagesFor the context variable. ThispagesA variable is a very powerful object that carries all the key information of the current pagination state. And the protagonist of today - the current page number, is stored inpagesthe object'sCurrentPagein the field.

To get and display the current page number, the operation is extremely concise and intuitive, you just need topaginationreference it within the tag, by using the double brace syntax:

当前页码:{{pages.CurrentPage}}

Isn't it very simple? This line of code can directly output the current page number on your web page. For example, if the user is browsing the second page, it will display '2'.

Build a complete pagination navigation in practice

It is often not enough to just display the current page number, usually we will integrate it into the entire pagination navigation to provide a more comprehensive user experience. Now, let's see a more complete example, combining the current page number with the total number of pages, first page, last page, previous page, next page, and the list of middle page numbers:

{# 假设我们正在某个列表页,首先需要获取分页数据 #}
{% archiveList archives with type="page" limit="10" %}
    {# 这里是文章列表的循环内容,省略以便聚焦分页 #}
    {% for item in archives %}
        <div class="article-item">
            <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
            <p>{{item.Description}}</p>
        </div>
    {% endfor %}
{% endarchiveList %}

{# 接着,使用 pagination 标签构建分页导航 #}
<div class="pagination-container">
    {% pagination pages with show="5" %}
        <p class="pagination-summary">
            总共 <span>{{pages.TotalPages}}</span> 页,当前第 <span>{{pages.CurrentPage}}</span> 页
        </p>

        <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 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 example, we can clearly seepages.CurrentPagehow it is withpages.TotalPagesto provide the context information of the current page. At the same time,pagesThe object also providesFirstPage/PrevPage/NextPage/LastPageAn object that can be directly referenced, as well as an array containing all the intermediate page numberspages.Pagesfor eachitemareLinkandIsCurrentAttribute, allowing us to easily implement dynamic highlighting of the current page number style. This way of providing structured data greatly simplifies the development of front-end pagination components.

Summary

AnQiCMS provides intuitive and powerful pagination support at the template level. ThrougharchiveList(or other list tags)配合type="page", then usepaginationtag to obtainpagesAn object, and we can easily obtain and display includingpages.CurrentPageAll pagination information within. This not only improves our development efficiency, but also ensures that the pagination experience of the website remains consistent and optimized across different content types.As an operator, mastering these template skills can make us more proficient in content management and website optimization.


Frequently Asked Questions (FAQ)

1. Q: How to get the total number of pages or entries in AnQiCMS template?

Answer: InpaginationInside the tag, you can directly access through{{pages.TotalPages}}Get the total number of pages and through{{pages.TotalItems}}This information is usually displayed with the current page number, providing users with a comprehensive pagination overview.

2. Ask: I used in the template{{pages.CurrentPage}}but it did not display any content, what is the reason?

Answer: This situation usually occurs when the current page is not a pagination list page, or when the tag used to obtain the list (such asarchiveList/categoryList/tagDataList) is not set correctlytype="page"Parameter.pagesAn object is only initialized when the page data is explicitly requested. Please check if your list tag has settypeis set to"page"Make sure you are on a page that actually triggers pagination (for example, bylimitthe parameter limits the number of items displayed, resulting in multiple pages).

3. Q: Besidespages.CurrentPageHow can I customize the display of pagination links, for example, controlling the number of page numbers displayed in the middle?

Answer:paginationTags providedshowParameter, which you can use to control the number of page numbers displayed in the middle page number list, for example,{% pagination pages with show="7" %}。“Furthermore,”pages.Pagesis an array containing all the intermediate page numbers, you can iterate through this array and combine it with each page item'sitem.IsCurrentTo determine if it is the current page, so that different CSS styles (such as highlighting) can be applied, realizing fully customizable page navigation styles.

Related articles

What do `pages.TotalItems` and `pages.TotalPages` represent in pagination tags, and what scenarios can they be used in?

As an experienced website operations expert, I know that a powerful and flexible content management system is crucial for the success of a website.AnQiCMS (AnQiCMS) boasts its efficient architecture based on the Go language and rich features, providing great convenience for content operators.Today, with the content of websites becoming increasingly rich, how to efficiently display and manage this content while providing an excellent user experience is a topic that every operator must face.The pagination mechanism is one of the core means to solve this problem.Today, we will deeply analyze the two key variables in the Anqi CMS pagination tag

2025-11-07

How to determine the current page based on `pages.FirstPage.IsCurrent` or `item.IsCurrent` and add special CSS styles to it?

As an experienced website operations expert, I know how crucial clear navigation and page state indicators are in terms of user experience and search engine optimization (SEO).AnQiCMS (AnQiCMS) with its flexible and powerful template engine provides us with many conveniences, including the ability to accurately judge the current page status through boolean variables such as `pages.FirstPage.IsCurrent` or `item.IsCurrent` and add special CSS styles for it.This can not only significantly improve the user's browsing experience

2025-11-07

How to customize the text content of the 'First Page', 'Previous Page', 'Next Page', 'Last Page' pagination tags in AnQiCMS templates?

As an experienced website operations expert, I am well aware of the importance of website details in user experience and brand image.AnQiCMS (AnQiCMS) with its flexible template mechanism and strong multilingual support, allows us to easily meet these customization requirements.Today, let's delve into how to precisely customize the pagination labels such as 'Home', 'Previous', 'Next', and 'Last Page' in the AnQiCMS template, making your website's pagination not only functional but also full of brand characteristics.### Understand AnQiCMS

2025-11-07

What is the role of the `show` parameter of the `pagination` tag? How to control the number of page numbers displayed at the bottom of the page?

As an experienced website operations expert, I know that it is crucial to effectively guide users to browse and discover information when managing a large amount of content.The pagination feature is the bridge that connects users to the deep content of the website.In AnQiCMS (AnQiCMS) such an efficient and customizable content management system, flexible use of pagination tags can greatly enhance user experience and the professionalism of the website.Today, let's delve into a core parameter of the `pagination` tag in AnQiCMS, namely `show`, and see what its role is

2025-11-07

How does the `archiveList` tag work with the `pagination` tag to implement pagination when using the `type="page"` mode?

In AnQiCMS content management system, efficiently displaying a large amount of content and ensuring a good user experience and search engine optimization is the key to successful operation.Among these, the pagination display of the content list undoubtedly plays a core role.

2025-11-07

How to combine the `commentList` tag with the `pagination` tag to implement pagination of comment content?

Hello! As an experienced website operations expert, I am very willing to delve into how to巧妙ly combine `commentList` and `pagination` tags in AnQiCMS to achieve the pagination display of comment content, making user interaction smoother and more orderly.In today's content-driven era, user comments are not only a symbol of website vitality but also an important embodiment of content value.However, if a popular article accumulates a massive amount of comments, loading them all at once would undoubtedly put a huge burden on the page, severely affecting user experience. At this time

2025-11-07

How to use the `pagination` tag to create pagination for the document list under the specified Tag?

As an experienced website operations expert, I am well aware of the importance of content organization and user experience in today's digital world.In an efficient and feature-rich system like AnQiCMS, how to present a large amount of content to users in the most user-friendly way while also considering search engine optimization is a topic that requires continuous thinking and practice.Today, let's delve deeply into a practical and powerful combination in Anqi CMS: how to skillfully use the `tagDataList` tag in conjunction with the `pagination` tag

2025-11-07

Does AnQiCMS support custom pagination URL structure for its pagination tag? What is the specific usage of the `prefix` parameter?

AnQiCMS Pagination Tag and Custom URL Structure: Deep Analysis of `prefix` Parameter As an experienced website operations expert, I know how important it is to have a clear, SEO compliant, and user-friendly URL structure for a website.How to flexibly control pagination links, especially in content management systems, is a common concern for operators.AnQiCMS (AnQiCMS) took this into consideration from the very beginning, providing website administrators with a great degree of freedom through its powerful template engine and pseudo-static features. Today

2025-11-07