How to implement content pagination display and customize page navigation style in AnQiCMS template?

Calendar 👁️ 62

As the content of the website becomes richer, how to efficiently display a large amount of information while ensuring a user-friendly browsing experience is an indispensable part of website operation.In AnQiCMS, through the powerful template tag system, we can easily implement content pagination and flexibly customize the style of page navigation, making the website content rich and tidy.


Efficiently organize content: Implement pagination for content lists

In the AnQiCMS template, the core of implementing pagination for content is to usearchiveListTag to retrieve document lists. This tag is powerful, as it can not only list documents of specified categories or models, but can also be directly configured for pagination mode.

First, in your list page template (for example, the list page for the article model is usuallyarticle/list.htmlor a custom category list template) you will usearchiveListLabel. To enable pagination, you need to settypeparameters for"page"and utilizedlimitparameters to define the number of articles displayed per page. For example, if you want to display 10 articles per page, the code would look like this:

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
    <div class="article-item">
        <h2><a href="{{item.Link}}">{{item.Title}}</a></h2>
        <p>{{item.Description}}</p>
        <div class="meta">
            <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
            <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
            <span>阅读量:{{item.Views}}</span>
        </div>
    </div>
    {% empty %}
    <p>当前分类下暂时没有文章。</p>
    {% endfor %}
{% endarchiveList %}

In this code block,archiveListThe tag will load the article data that meets the conditions into a variable namedarchivesand automatically paginate according to thelimitparameters. Inforthe loop,itemit represents each article, you can access it throughitem.Title/item.Link/item.DescriptionAccess various properties of the article in this way.{% empty %}The tag handles the scenario very considerately when there are no articles to display, avoiding a blank page.

Fine-grained control: Customize page navigation style

After the content list is displayed, the next step is to provide users with convenient page navigation. AnQiCMS providespaginationLabel. This label will be based onarchiveListLabel generates the total number of pages and the current page number, automatically generating a link that includes home, previous page, specific page number, next page, and last page, etc.pagesobject for you to render flexibly in the template.

InarchiveListBelow the label, use it immediatelypaginationLabel, and can be配合showParameter to control the number of page numbers displayed in page navigation. For example,show="5"It means that the page navigation can display a maximum of 5 page number digits (such as 1, 2, 3, 4, 5).

This is a complete example that combines content lists and page navigation, and incorporates considerations for style customization:

{% archiveList archives with type="page" limit="10" %}
    <div class="article-list">
        {% for item in archives %}
        <div class="article-item">
            <h2><a href="{{item.Link}}">{{item.Title}}</a></h2>
            <p>{{item.Description}}</p>
            <div class="meta">
                <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>阅读量:{{item.Views}}</span>
            </div>
        </div>
        {% empty %}
        <p>当前分类下暂时没有文章。</p>
        {% endfor %}
    </div>

    <div class="pagination-nav">
        {% 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 %}

            {# 中间页码数字,遍历 pages.Pages 数组 #}
            {% for pageItem in pages.Pages %}
            <li class="page-item {% if pageItem.IsCurrent %}active{% endif %}">
                <a href="{{pageItem.Link}}">{{pageItem.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>
{% endarchiveList %}

In the abovepaginationInside the tag,pagesThe object provides rich information:

  • pages.TotalItemsandpages.TotalPagesThey represent the total number of articles and total pages.
  • pages.CurrentPageIt is the current page being visited.
  • pages.FirstPage/pages.LastPage/pages.PrevPage/pages.NextPageThey represent the navigation objects for the home page, last page, previous page, and next page, and they all containLink(link address) andName(Display text) attribute, as well as oneIsCurrentBoolean value to determine if it is the current page.
  • pages.Pagesis an array that contains the specific page numbers of the middle part, each element is also an array that containsLink/NameandIsCurrentThe object of the property.

By using these properties, you can easily customize the appearance of page navigation. For example, through{% if pageItem.IsCurrent %}active{% endif %}such conditional judgments, for the current page's<li>Element additionactiveA class is then created, and its highlight style is set using CSS. Similarly,{% if pages.PrevPage %}This judgment can ensure that the corresponding navigation link does not display when there is no previous page or next page, thus maintaining the simplicity of navigation.

Flexible and variable: practical suggestions for improving user experience

  1. CSS Customize AppearanceThe above example provides HTML structure and basicactiveThe specific page navigation beautification depends entirely on your CSS design. You can adjust the font, color, background, border, etc., to match the overall style of the website.
  2. Template File Location: Generally, the template file for the list page is placed intemplate/{您的模板目录}/{模型table}/list.htmlFor exampletemplate/default/article/list.html. If you have a specific category that requires a different list layout, AnQiCMS also supports{模型table}/list-{分类id}.htmlsuch custom templates.
  3. Combine search functionality: If your website contains a search function,archiveListThe tag is intype="page"mode, it will automatically read the URL inqThe parameter is used as a search keyword to implement pagination of search results. You do not need to handle the search results extra.

Related articles

How to display the article list according to different sorting rules (such as latest, views, custom sorting)?

Managing website content in Anqi CMS, flexibly controlling the display order of article lists is crucial for improving user experience and content distribution efficiency.Whether you want to immediately display the latest released content to visitors, highlight the most popular hot articles, or manually adjust the arrangement of articles according to specific operational strategies, Anqi CMS provides a simple and powerful way to meet these needs.One of the core advantages of AnQi CMS is its intuitive and feature-rich template tag system.

2025-11-08

How to filter and display articles in a list or category list based on recommended attributes (such as "Top Story

In content management and website operation, how to effectively highlight key information, guide users to focus on specific articles, is the key to improving website effectiveness.AnQiCMS (AnQiCMS) provides a flexible recommendation attribute feature that allows you to easily filter and display articles in article lists or category lists based on attributes such as "Headline" and "Recommended", thus better realizing content operation strategies.

2025-11-08

How to dynamically display different group Banner slideshows on the website homepage?

The banner carousel on the homepage is an important window to attract visitors' attention and convey core information.By cleverly setting up, we can allow the home page banner slideshow to dynamically display according to different marketing goals or content themes, which can not only improve user experience but also effectively guide users to browse.AnQiCMS (AnQiCMS) offers flexible features to help users easily meet this requirement.Understanding the Banner mechanism of AnQi CMS In AnQi CMS, the management and display of banners have a clear logic

2025-11-08

How to implement the switching display of multilingual website content and adapt to users of different languages?

Today, with the deepening of globalization, a website that supports multilingualism has become a basic requirement for enterprises to expand into international markets and serve global users.AnQiCMS deeply insight into this trend, providing users with a highly efficient and flexible multilingual website content management solution, helping your website easily switch between different language content display and better adapt to users around the world.The core concept of AnQiCMS implementing multi-language website content switching is based on multi-site management.

2025-11-08

How to implement a search function on the front end of a website and display a list of search results with highlighted keywords?

When building a rich website, providing an efficient and convenient search function is a key aspect of improving user experience.AnQiCMS (AnQiCMS) has fully considered this from the beginning of its design, through its flexible template engine and built-in tags, we can relatively easily implement search functionality on the website front-end, and further optimize it to make the keywords in the search results stand out and highlight prominently.### Core Mechanism: Understanding the Search Principle of AnQiCMS The core of AnQiCMS website frontend search lies in `search/index.html`

2025-11-08

How to implement filtering in the article list based on custom parameters (such as product features, price range)?

In website operation, we often need to classify and filter content lists more finely to help users quickly find the information they are really interested in.Traditional article classification can solve most problems, but when the content attributes become more complex, such as products with multiple characteristics, price ranges, or events with different themes and participation methods, a single classification seems to be inadequate.

2025-11-08

How to display the link and title of the previous and next article in AnQiCMS template?

It is crucial to provide visitors with a smooth navigation experience in website operation.When a user finishes reading an article, they naturally expect to find more related content, and the "Previous" and "Next" links are the key features to meet this need.They can not only improve the user's stay time on your website, but also have a positive impact on search engine optimization (SEO) by building an internal link structure.AnQiCMS provides concise and efficient built-in tags for template developers, allowing you to easily display links and titles of the previous and next articles on the article detail page.

2025-11-08

How to display a list of related documents on the document detail page, such as categorized recommendations or keyword-based recommendations?

In website content operation, providing more relevant and potentially interesting content to visitors is a key strategy to enhance user experience, extend website stay time, and promote in-depth content browsing.This not only effectively guides users to explore more information, but is also an important component of 'inter-page relevance' in Search Engine Optimization (SEO).In such a powerful content management system as AnQiCMS, it is easy and efficient to implement the display of related document lists on the document detail page.

2025-11-08