How to display a list of articles with pagination and customize the style and number of pagination navigation pages?

Calendar 👁️ 98

Today, with the rich content of websites, how to efficiently display a large number of articles while ensuring a smooth user browsing experience is a problem that every website operator needs to think about.AnQiCMS (AnQiCMS) offers a powerful and flexible pagination feature for article lists, which not only helps optimize the presentation of website content but also integrates better with the overall website design through custom styles and page number settings, enhancing user interaction experience.

Next, we will delve into how to implement pagination display of article lists in Anqi CMS, and we will give a detailed explanation of how to customize the style and number of pagination navigation according to your needs.


One, implement the pagination display of the article list

In Anqi CMS, to display the article list in pagination, the core lies in using template tagsarchiveListto obtain the data and specify it as pagination mode.

First, you need to use the template file (usually the list page template, such as{模型table}/list.htmlor a custom list template) in usearchiveListThe label is used to retrieve article data. This label is very flexible, and can be used to filter articles based on various conditions such as category ID, model ID, recommendation attributes, etc.

The key is to providearchiveListLabel settingstype="page"The parameter. Once set, the Anqin CMS will automatically handle the pagination logic of the current page, based on your specificationslimitThe parameter (number of articles per page) is used to return the articles on the current page.

For example, if you want to display 10 articles per page under the current category, you can write the code like this:

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
    <div class="article-item">
        <a href="{{item.Link}}">
            <h4>{{item.Title}}</h4>
            <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>
        </a>
        {% if item.Thumb %}
        <a href="{{item.Link}}">
            <img src="{{item.Thumb}}" alt="{{item.Title}}">
        </a>
        {% endif %}
    </div>
    {% empty %}
    <p>抱歉,当前分类暂无文章。</p>
    {% endfor %}
{% endarchiveList %}

In this code block:

  • archiveList archives with type="page" limit="10"Will retrieve 10 articles corresponding to the current page number and store the results inarchivesthe variable.
  • {% for item in archives %}Loop through these articles,itemThe variable contains detailed information about each article, such as the title,item.Title) and link (item.Link), Description (item.Description) and so on.
  • {% empty %}A block is used to display a friendly prompt when there is no article data, to avoid the page from being blank.

In this way, you have successfully enabled pagination for the article list. Next, we need to provide users with a tool to navigate to different page numbers.


II. Render pagination navigation

After the article list data is ready, it needs to be usedpaginationtags to generate and display the pagination navigation.paginationTags usually follow.archiveListAfter the tag is used, it will depend onarchiveListThe provided pagination information, automatically generates page number links and navigation buttons.

paginationTags will organize the pagination data into apagesAn object, which contains various useful information about the current pagination state, such as the total number of articles, total number of pages, current page number, home link, previous page link, next page link, end page link, and an array containing all visible page numbers.

A basic pagination navigation implementation may look like this:

<div class="pagination-container">
    {% pagination pages with show="5" %}
    <ul>
        {# 首页按钮 #}
        <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>
    <p>总共有 {{pages.TotalItems}} 篇文章,分为 {{pages.TotalPages}} 页,当前在第 {{pages.CurrentPage}} 页。</p>
    {% endpagination %}
</div>

In this code block:

  • {% pagination pages with show="5" %}Tell the system to generate pagination navigation and store the pagination data inpagesthe variable.show="5"The parameter plays a crucial role here, it indicates that in the page number list, in addition to the home page, end page, previous page, and next page buttons, at most 5 middle page numbers are displayed (for example, when the total number of pages is very large, it will display1...3 4 5 6 7...100)
  • pages.FirstPage/pages.PrevPage/pages.NextPage/pages.LastPageObjects representing the home, previous, next, and end pages, theirLinkproperties provide corresponding links,Nameproperties provide button text.
  • pages.PagesIt is an array that contains the middle page number items. Through{% for item in pages.Pages %}Loop traversal,item.LinkProvide page link,item.NameProvide page number.
  • item.IsCurrentorpages.FirstPage.IsCurrentBoolean values can determine whether the current page number is the one being viewed, which is crucial for highlighting the current page number.

Section 3: Customizing the style and number of pagination navigation

The AnQi CMS pagination tag provides sufficient flexibility, allowing you to achieve complete customization of styles by controlling tag parameters and pairing with CSS.

1. Customize page number count:As mentioned before,paginationlabel'sshowThe parameter directly controls the number of middle page number buttons.

  • show="5": Up to 5 middle page numbers are displayed.
  • show="7"The maximum number of middle page numbers displayed is 7. You can adjust this number based on the width of the page layout, user habits, and other factors to achieve the desired display effect. If omittedshowParameters, the system will have a default value, but for precise control, it is recommended to set it explicitly.

2. Customize pagination navigation style:By adding a custom CSS class to the HTML structure, you can fully control the visual presentation of pagination navigation.

In the above example, we usedpagination-container/page-itemandactiveName classes. You can write style rules for these classes in your CSS file, for example:

/* pagination-container 整体布局 */
.pagination-container {
    margin-top: 30px;
    text-align: center;
}

.pagination-container ul {
    list-style: none;
    padding: 0;
    display: inline-flex; /* 使页码水平排列 */
    margin: 0;
}

/* page-item 单个页码或按钮 */
.page-item {
    margin: 0 5px; /* 页码间距 */
}

.page-item a {
    display: block;
    padding: 8px 12px;
    border: 1px solid #ddd;
    color: #333;
    text-decoration: none;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

.page-item a:hover {
    background-color: #f5f5f5;
    color: #007bff;
    border-color: #007bff;
}

/* active 当前页高亮 */
.page-item.active a {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
    pointer-events: none; /* 禁用当前页的点击事件 */
}

/* 隐藏不必要的文字(如首页/尾页按钮的默认文本在某些设计中可能不显示) */
.page-item:first-child a,
.page-item:last-child a {
    font-weight: bold;
}

By modifying these CSS rules, you can change the background color, text color, border, rounding, size, and even add animation effects to the pagination button, making it perfectly match the design style of your website.


Advanced Techniques and Precautions

  • Pagination of Search Results: archiveListlabel'sqThe parameter is intype="page"This also works in the mode. This means that if you use the tag on the search results page, it will automatically identify the search keywords in the URLqand

Related articles

How to retrieve and display the list of Banner carousel images configured on the website homepage?

In Anqi CMS, the Banner slideshow on the homepage is an important element to attract visitors' attention and display core content.Correctly obtain and display these banner images, which can greatly enhance the visual effects and user experience of the website.Anqi CMS provides intuitive functions and flexible template tags, allowing us to easily achieve this goal. ### First Step: Configure Your Banner Carousel in the Backend Before starting to display the Banner on the website frontend, we first need to configure it in the Anqi CMS backend management system. Typically

2025-11-08

How to retrieve and loop the list of friend links in the AnQiCMS template?

In website operation, friendship links are an important means to enhance website authority, increase external traffic, and promote cooperative relations.A convenient management and flexible display of友情链接 function is crucial for any content management system.AnQiCMS as an efficient content management system provides an intuitive way to manage and obtain the list of friend links in templates.This article will thoroughly introduce how to obtain and loop through the list of friendship links on AnQiCMS templates, helping you easily realize the interconnection of websites.

2025-11-08

How to get the complete content, SEO information, and associated images of a single page?

In daily website operations, independent pages such as "About Us", "Contact Information", etc., play an important role in conveying core information and shaping the brand image.As content operators, we often need to gain a deep understanding of the structure of these pages, including their main content, SEO information, and all associated image resources, in order to carry out fine management, optimization iteration, or flexible page layout.AnQiCMS provides an intuitive and powerful template tag system, making it easy to obtain these page data.

2025-11-08

How to get and loop through all independent pages in AnQiCMS template (such as About Us)?

In AnQi CMS, sometimes we need to list some independent pages in the website's navigation bar, footer, or other specific areas, such as "About Us", "Contact Us", "Privacy Policy", and so on.These pages usually contain fixed content and do not belong to a specific category or article model. AnQiCMS refers to them as 'single pages'.Fortunately, AnQiCMS provides a very intuitive and powerful template tag that can easily retrieve and loop through information for these single pages.### Core Tag

2025-11-08

How to dynamically add a website name suffix or custom delimiter in the page title (Title)?

The page title (Title) is the 'front door' of a website on the search engine results page. It not only can intuitively tell users the content of the page, but it is also an important indicator for search engines to evaluate the relevance and authority of the page.An optimized page title that can significantly improve click-through rates and the website's search engine ranking.In AnQiCMS, you can flexibly control the way page titles are generated, especially by dynamically adding the website name suffix and custom delimiters to achieve a unified brand image and better SEO effect.### AnQiCMS in TDK

2025-11-08

How to implement search through URL parameters (such as `q=keyword`) on the article list page and display the results?

It is crucial to provide users with a convenient and accurate content search experience in website content operation.When the number of articles on the website continues to grow, a practical search function can greatly enhance user satisfaction and the efficiency of content access.AnqiCMS as an efficient content management system provides a flexible way to implement the URL parameter search function for the article list page, allowing visitors to directly search and view related content by adding parameters such as `q=keywords` to the URL.

2025-11-08

How to combine custom parameters (such as "area", "house type") for multi-condition filtering on the article list page?

In AnQi CMS, to implement multi-condition filtering on the article list page, such as filtering based on custom parameters such as "area" and "house type", it requires us to cleverly combine the system-provided "content model" feature with the "document parameter filtering tag" ("archiveFilters") and "document list tag" ("archiveList") of the front-end template.The entire process can be divided into several core steps, let's take a detailed look together.### Core Function: Customize Content Model and Parameters Basic Implementation of Multi-Condition Filtering

2025-11-08

Besides `stampToDate`, which filters can format time values into a specified date format?

In AnQi CMS template development, we often need to display the time values stored in the database, such as the publication time and update time of articles, in the date and time format we expect.The `stampToDate` filter is undoubtedly one of the most commonly used and powerful tools, which can flexibly convert Unix timestamps to various date formats.

2025-11-08