How to implement user-friendly pagination navigation display for the article list?

Calendar 👁️ 61

The article list is the core display area of the website content, its user experience directly affects the visitor's stay time and willingness to revisit.When the number of articles is large, a reasonable page navigation design is particularly important.AnQiCMS (AnQiCMS) provides powerful and flexible template tags, helping us easily implement user-friendly article list pagination functions, making content management and display more efficient.

Core feature analysis: Anqi CMS article list and pagination mechanism

In Anqi CMS, the implementation of pagination for article lists mainly relies on two core template tags: archiveListandpagination.archiveListresponsible for retrieving article data from the database and organizing it into a list suitable for template rendering; whereaspaginationthen based onarchiveListThe data provides various links and information required for pagination navigation. Combined with them, it can build a complete and style-controllable article list pagination display.

archiveListThe tag can not only obtain the usual article list but also handle various scenarios such as related articles, search results, etc. When we need to display pagination, we just need to specifytype="page"The parameter, AnQi CMS will automatically handle the current page number, total number of pages, and other data for subsequent pagination tags.

paginationTags focus on generating pagination navigation.It provides rich properties such as the total number of articles, total number of pages, current page number, and links and statuses to the first page, previous page, next page, last page, and middle page numbers, allowing us to finely control the display logic of pagination navigation.

Step 1: Get the pagination article list data

First, we need to use in the template filearchiveListLabel to retrieve the data of articles that need to be displayed in pagination. Suppose we want to display articles under a certain category on a page, showing 10 articles per page, and enable pagination, the code would be something like:

<div class="article-list-container">
    {% archiveList archives with type="page" limit="10" categoryId="1" %}
        {% for item in archives %}
            <article class="article-item">
                <h2><a href="{{item.Link}}">{{item.Title}}</a></h2>
                <p class="article-meta">
                    发布于:{{stampToDate(item.CreatedTime, "2006-01-02")}}
                    浏览量:{{item.Views}}
                </p>
                <p class="article-description">{{item.Description}}</p>
                <a href="{{item.Link}}" class="read-more">阅读全文 &raquo;</a>
            </article>
        {% empty %}
            <p>当前分类下还没有任何文章。</p>
        {% endfor %}
    {% endarchiveList %}
</div>

In this code block,archiveListThe tag assigns the list of articles obtainedarchivesto the variable. The key istype="page", it tells the system that we need to enable pagination mode;limit="10"which limits the number of articles displayed per page;categoryId="1"Specified the article we want to get under the category with ID 1.forIn the loop, we can display the detailed information of each article byitem.Title/item.Linketc.{% empty %}The block handles the prompt information when the article list is empty, improving the user experience.

Step 2: Build user-friendly pagination navigation display.

After the article list data is retrieved, the next step is to usepaginationtags to create pagination navigation. This tag usually followsarchiveListthe tag and usearchiveListGenerated pagination data to render navigation elements. Here is a common pagination navigation structure:

<nav class="pagination-nav">
    {% pagination pages with show="5" %}
        <span class="pagination-info">总计 {{pages.TotalItems}} 篇文章,共 {{pages.TotalPages}} 页,当前第 {{pages.CurrentPage}} 页</span>
        <ul class="pagination-links">
            {# 首页链接 #}
            {% if pages.FirstPage %}
                <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
                    <a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
                </li>
            {% endif %}

            {# 上一页链接 #}
            {% 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 %}

            {# 末页链接 #}
            {% if pages.LastPage %}
                <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
                    <a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
                </li>
            {% endif %}
        </ul>
    {% endpagination %}
</nav>

in thispaginationTagged,pagesThe variable contains all pagination-related information.show="5"The parameter indicates that up to 5 page number buttons can be displayed before and after the current page to avoid confusion caused by too many page numbers. We usepages.TotalItems/pages.TotalPagesandpages.CurrentPageto display the total pagination information.

What's more, by usingpages.FirstPage/pages.PrevPage/pages.NextPageandpages.LastPagePerform a conditional judgment ({% if ... %}We can intelligently display or hide navigation buttons such as 'Home', 'Previous Page', 'Next Page', 'End Page' to ensure they only appear when needed.{% for item in pages.Pages %}The loop is used to iterate over the middle page number buttons and according toitem.IsCurrentThe attribute adds to the current page numberactiveThe class to highlight it through CSS, enhancing user recognition.

Integration and Optimization: Enhance User Experience

Place the above two parts of code on the same page template (for examplearticle/list.htmlorsearch/index.htmlIn this way, you can implement pagination for the article list.To make the pagination navigation truly user-friendly, in addition to the above logical implementation, it is also necessary to combine CSS styles for beautification.pagination-linksAdd padding, border, background color, and other properties to the list items andactiveSet a prominent color so that users can identify the current page at a glance.

This label-based design of AnQi CMS decouples data acquisition and pagination logic, making the template code clear and easy to understand, and also more convenient for later maintenance and modification.Whether it is a blog with frequent content updates or an e-commerce website with a large number of products, it can provide visitors with a smooth and intuitive browsing experience in this way.

Frequently Asked Questions (FAQ)

1. How to adjust the number of articles displayed per page?You can modify byarchiveListin the labellimitParameters to adjust the number of articles displayed per page. For example, settinglimit="10"changed tolimit="20"will allow 20 articles to be displayed per page.

2. How to implement pagination on the search results page?Of Security CMSarchiveListThe tag is intype="page"In mode, it will automatically identify the parameters in the URL.qAs search keywords. Therefore, you do not need to configure extra, just make sure the name of the keyword parameter submitted in the search form is.qand then inarchiveListUsed in tagstype="page"You can implement pagination of search results. If you need to specify a search keyword, you can also inarchiveListthe tag throughq="您的关键词"Set the parameters.

3. How can I only display the 'Previous Page' and 'Next Page' buttons without showing the specific page numbers?You can modify it.paginationLoop structure within tags. Just delete or comment out.{% for item in pages.Pages %}to `{% endfor %}`}]

Related articles

How does AnQiCMS display the latest article list and its publication time on the front end?

In website operation, displaying the latest published content to visitors in a timely manner can not only effectively improve user experience but also enhance the activity of the website.AnQiCMS (AnQiCMS) provides an intuitive and powerful template tag feature, allowing you to easily display the latest article list and its publication time on the website front page. ### Understanding Anqi CMS Article Display Mechanism Anqi CMS uses template tags to call and display website data.

2025-11-08

How to accurately display the field data of a custom content model on the front-end page?

In AnQiCMS, we often need to create various types of content according to the actual needs of the website.AnQiCMS's powerful custom content model feature is designed to meet this flexibility.It allows us to define dedicated fields for different types of content (such as articles, products, cases, etc.), thus enabling more precise management and display of information.How can we accurately call and display these custom field data on the website's front page?

2025-11-08

How to customize the content display layout of the article detail page in AnQi CMS

AnQi CMS has excellent flexibility in content display, especially for article detail pages, it provides multi-level customization options, allowing us to finely control the layout of content display according to specific needs, whether it is for the entire model, specific categories, or an independent article.This not only involves adjustments in appearance, but also includes in-depth customization of the page content structure and information presentation.

2025-11-08

How do Sitemap, Robots.txt, and other advanced SEO tools in AnQiCMS affect the visibility of website content in search engines?

During the journey of website operation, we all hope that our content can be discovered by more potential users.And the search engine is undoubtedly the most important bridge connecting websites to users.To ensure that this bridge is unobstructed, our website needs to communicate effectively with search engines.

2025-11-08

How to filter and display related article lists on the front page according to the specified category ID?

In Anqi CMS, it is actually very simple to filter and display a list of related articles on the front page according to the category ID!The AnQi CMS, with its efficient and flexible features, makes content management and display easy.No matter if you are running a corporate website, an industry information station, or a personal blog, you may encounter the need to display a list of articles according to a specific category.For example, display articles from a certain "Hot Recommendation" category on the homepage, or showcase specific "Product Cases" on a special topic page.Today, let's talk about how to accurately implement this function in the Anqi CMS front-end template.###

2025-11-08

How to display the links to the previous and next articles at the bottom of the article detail page?

In website content operation, improving user reading experience is a key link.After a reader has finished browsing an excellent article, if they can immediately see a link to the next related or sequential article, it will undoubtedly greatly increase the likelihood that they will continue to stay on the website.This design not only optimizes the user experience, helps guide users to delve deeper into the website's content, but also effectively reduces the bounce rate and enhances the website's SEO performance, allowing search engines to better understand the structure of your website's content.

2025-11-08

How to aggregate and display a list of selected articles under multiple categories on a single page?

In website operation, we often encounter such needs: on the homepage or a special topic page, we can display selected articles from different categories, which can enrich the page content and guide users to discover more interesting information.AnQiCMS provides very flexible and powerful features, allowing us to easily achieve this goal without complex programming knowledge.

2025-11-08

How does AnQiCMS provide visitors with language switching options for content display?

In today's globally interconnected digital age, websites have become a basic need to provide content for users of different languages.No matter whether your business is aimed at the global market or simply wants to cover users in different dialect regions within the country, a website that supports multilingual switching can significantly improve user experience and brand influence.AnQiCMS (AnQiCMS) fully understands this need and provides an efficient and flexible solution to help your website seamlessly switch between multilingual content.

2025-11-08