In the `pagination` tag, how to determine if the current page is the first or last page to control the style?

Calendar 👁️ 63

As an experienced website operations expert, I know the importance of a powerful and flexible content management system for the success of a website.AnQiCMS leveraging its efficient features of the Go language and in-depth consideration of content operation, provides us with many conveniences.paginationThe versatility of pagination tags, especially how to accurately determine whether the current page is the first or last page, thus flexibly controlling the style to create a more smooth and intuitive navigation experience for users.

The core of AnQiCMS pagination tags: understandpagesobject

In the world of AnQiCMS templates,paginationTags are the core tools for handling pagination logic. They are usually associated witharchiveListThis list tags work together to package all pagination-related data into an object namedpages. ThispagesThe object contains rich information about the current list page, such as the total number of items,TotalItems), Total number of pages (TotalPages)、current page (CurrentPage) and so on.

To achieve the topic we are discussing today - determining whether the current page is the first or last page and controlling the style, the most critical attribute is undoubtedly the page number objects (includingpages.FirstPage/pages.LastPageas well aspages.PagesEach in the arrayitemAll haveIsCurrentfield. It is a boolean value, which is true only when the page is the current visited page, its value istrue. It is this tiny boolean value that gives us the ability to precisely control the page style.

Precisely judge and control the home page style.

When a user is browsing the list page, the homepage usually has a special meaning.We may hope that when the current page is the homepage, we should give the "homepage

To determine if the current page is the homepage, we can directly utilizepages.FirstPage.IsCurrentthe attribute. When this attribute istrue, there is no doubt that the user is on the first page.

In the template, you can handle the style of the "Home" link in this elegant way:

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

The above code will be based onpages.FirstPage.IsCurrentvalue, dynamically add or remove<li>elementsactiveThus, the class can be used to highlight or distinguish visually.

As for the 'Previous Page' button, when the page is on the first page, it should be unclickable. AnQiCMS'spagesThe object provides very consideratelypages.PrevPagethe property. If the current page is the first page, thenpages.PrevPageit will benil(empty value), we can use this to control its clickable state:

{% if pages.PrevPage %}
    <li class="page-item">
        <a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
    </li>
{% else %}
    <li class="page-item disabled">
        <span>上一页</span> {# 此时没有上一页链接,显示为不可点击的文本 #}
    </li>
{% endif %}

In this way, we not only controlled the style, but also disabled the invalid operation of clicking "Previous page" on the homepage, improving the user experience.

Flexible control of the style of the last page.

This logic is similar to the home page, we also need to pay special attention to the end page.When the user scrolls to the end of the list, disable the "next page" and "last page" links, which can clearly inform the user that there is no more content, avoiding unnecessary clicks.

Determine whether the current page is the last page, the idea is consistent with the first page, we still rely onpages.LastPage.IsCurrentattribute. When its value istrue, the current page is the last page.

This is an example of the style control for the "last page" link:

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

Similarly, for the "next page" button, it should be disabled when on the last page. We can check bypages.NextPageTo implement the property:

`twig {% if pages.NextPage %}

<li class="page-item">
    <a href="{{pages.NextPage

Related articles

How to conditionally output the standard link according to the `CanonicalUrl` tag in AnQiCMS templates?

Hello! As an experienced website operations expert, I fully understand that in daily work, we not only need to pay attention to the quality of the website content, but also to the impact of technical details on SEO.The canonical URL is one of the crucial details that can effectively solve the problem of duplicate website content, concentrate page authority, and thus improve search engine rankings.Today, let's delve deeply into how to intelligently and elegantly output standard links based on the existence or absence of the `CanonicalUrl` field within the `tdk` tag in AnQiCMS templates

2025-11-06

How to determine if the `linkList` friendship link tag list is empty to avoid displaying an empty tag?

As an experienced website operations expert, I have accumulated rich experience in content management and template optimization in AnQiCMS.I know well that a smooth, beautiful and quick-loading website cannot be separated from the meticulous refinement of every detail.Today, let's delve deeply into an issue that is often overlooked in template development but is crucial for user experience and page neatness: how to avoid displaying redundant empty tags when the `linkList` friendship link tag list is empty.Avoid displaying empty tags: AnQi CMS

2025-11-06

How to determine if the `navList` menu item has child navigation (`item.NavList`) and perform nested rendering?

## AnQi CMS navigation menu: skillfully use `navList` to implement multi-level nesting and child navigation judgment As an experienced website operations expert, I fully understand the importance of a clear and flexible navigation system for user experience and the overall architecture of the website.In AnQiCMS (AnQiCMS), the `navList` tag is the core tool we use to build a powerful navigation system.

2025-11-06

How to highlight the current page in the `navList` navigation menu based on the `IsCurrent` property?

In the fast-paced digital world, a clear and intuitive website navigation menu is the foundation of a good user experience.As an experienced website operations expert, I am well aware of AnQiCMS's powerful capabilities in providing efficient and customizable content management solutions.It not only performs excellently but also considers the operator's needs in detail, for example, the built-in `navList` tag combined with the `IsCurrent` attribute can easily highlight the current page, greatly enhancing the professionalism and user-friendliness of the website.

2025-11-06

How to conditionally display the 'Previous' and 'Next' buttons in the `pagination`?

As an experienced website operation expert, I am willing to analyze the conditional display techniques of the pagination navigation buttons in AnQi CMS in detail.AnQi CMS is known for its efficiency and flexibility, its template engine provides powerful functions, allowing us to easily achieve both beautiful and practical page interactions.In website content management, pagination is an indispensable element, and how to intelligently display the "Previous Page" and "Next Page" buttons is directly related to the smoothness of the user's browsing experience.### SecureCMS

2025-11-06

How to judge whether the comment (`Status`) in the AnQiCMS template has passed the review and be displayed differently?

As an experienced website operation expert, I know the importance of the comment system for website user interaction and content ecology.In such a powerful content management system as AnQiCMS, flexibly controlling the display of comments, especially the differentiated display based on the review status, is a key factor in improving user experience and maintaining the quality of website content.Today, let's delve into how to use the `commentList` tag in the AnQiCMS template to judge the `Status` field of comments and implement intelligent differentiated display.

2025-11-06

How to determine if a comment in `commentList` has a parent comment (`Parent`) and display the reply structure?

As an experienced website operations expert, I fully understand how to effectively display user comments in content management, especially comments with reply structures, which are crucial for enhancing user interaction and website activity.AnQiCMS (AnQiCMS) relies on its powerful template engine and flexible data tags to make this requirement easily achievable.Today, let's delve into how to cleverly judge whether a comment has a parent comment in the AnQiCMS `commentList` tag and elegantly present a clear reply structure.

2025-11-06

How to dynamically add a required asterisk or hint based on the `Required` property of the `guestbook` form label?

As an experienced website operation expert, I know that every detail can affect user experience and operation efficiency.When building a website, forms are an important part of interacting with users, and clear, friendly form design is the key to improving conversion rates.AnQiCMS (AnQiCMS) with its flexible template engine and powerful backend management features, has provided us with great convenience, especially in handling scenarios such as message forms that require users to fill in information.Today, let's delve deeply into a seemingly simple but extremely practical skill: how to use the `Required` field of the back-end field

2025-11-06