How to implement pagination for the article list display function?

Calendar 👁️ 58

As an experienced website operator who deeply understands the operation of AnQiCMS, I understand that it is crucial to organize and present a large number of articles efficiently in content display.The pagination feature not only greatly enhances the user's browsing experience, but also avoids the visual fatigue caused by too much content on a single page, and is an indispensable part of SEO strategy.To implement pagination display of article lists in AnQiCMS, it benefits from its flexible template engine and dedicated tag system, making the whole process clear and efficient.

The core principle of implementing pagination display of the article list

The AnQiCMS content management system allows us to control the display of the website's frontend by defining template files. The pagination display function of the article list is essentially completed through the collaborative work of two core template tags: archiveListThe tag is responsible for retrieving article data from the database and performing pagination, andpaginationThe tag is responsible for generating pagination navigation links on the user interface. This clear division of labor ensures the effective separation of data logic from display logic, making template development more intuitive.

AnQiCMS template files follow a syntax similar to the Django template engine, variables are enclosed in double curly braces{{变量}}Definition, while conditional judgments, loop controls, and other logical operations use single curly braces and percent signs{% 标签 %}Definition, and tags usually appear in pairs. This provides strong support for us to build dynamic article lists and pagination navigation.

Template file preparation

In AnQiCMS, the article list page usually selects the corresponding template file based on the model type and category ID. According to the template production conventions, the list page template files are generally stored in/templateTemplates should be followed in the folder{模型table}/list.htmlor{模型table}/list-{文档分类ID}.htmlThe naming format. For example, if your article model table name isarticleand the list page is not bound to a specific category, then you may need to editarticle/list.htmlAdd pagination logic to the file. If your website uses a flat file organization mode, it may bearticle_list.htmlMake sure you are editing the correct list page template file.

Retrieve paginated article list data

Firstly, we need to utilize in the list page templatearchiveListThe tag is used to retrieve the article data that needs to be displayed in a paginated manner. This tag is the core tool used by AnQiCMS to query and display the article list. In order to implement pagination, we must converttypethe parameter to"page".

This is an example of retrieving a paginated list of article data:

{% archiveList archives with type="page" moduleId="1" limit="10" %}
    {% for item in archives %}
    <div class="article-item">
        <a href="{{item.Link}}">
            {% if item.Thumb %}
            <img src="{{item.Thumb}}" alt="{{item.Title}}">
            {% endif %}
            <h3>{{item.Title}}</h3>
            <p>{{item.Description}}</p>
        </a>
        <div class="article-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, we define a variable namedarchivesto store the article list data.type="page"Make sure to inform the system that pagination is required for this list.moduleId="1"Specified the model ID of the article (for example, 1 usually represents the article model).limit="10"Then it set the display of 10 articles per page.forIn the loop, we traversedarchiveseach article in theitem),and displayed the thumbnail, title, description, category, publish date, and reading volume of the article.emptyBlock displays a prompt message when there is no article.

Render pagination navigation

After successfully obtaining and displaying the paginated article list, the next step is to generate clickable pagination navigation links. AnQiCMS provides for thispaginationLabel. This label is usually followed byarchiveListlabel's{% endarchiveList %}.

The following is an example of rendering a pagination navigation:

<div class="pagination-container">
    {% pagination pages with show="5" %}
    <ul class="pagination">
        {# 首页链接 #}
        <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
            <a class="page-link" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
        </li>
        {# 上一页链接 #}
        {% if pages.PrevPage %}
        <li class="page-item">
            <a class="page-link" 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 class="page-link" href="{{item.Link}}">{{item.Name}}</a>
        </li>
        {% endfor %}
        {# 下一页链接 #}
        {% if pages.NextPage %}
        <li class="page-item">
            <a class="page-link" href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
        </li>
        {% endif %}
        {# 末页链接 #}
        <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
            <a class="page-link" href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
        </li>
    </ul>
    <div class="pagination-info">
        总计 {{pages.TotalItems}} 篇文章,共 {{pages.TotalPages}} 页,当前第 {{pages.CurrentPage}} 页。
    </div>
    {% endpagination %}
</div>

In this example, we will store the pagination information inpagesthe variable and setshow="5"To control the maximum number of middle page number links displayed in the pagination navigation. We generatepages.FirstPage/pages.PrevPage/pages.NextPageandpages.LastPagelinks for the home page, previous page, next page, and last page through the object. At the same time, throughpages.PagesThe array iterates to generate the middle page number links and passes throughIsCurrentAttribute determines the current page and addsactiveClass. In addition, it also displays the total number of articles, total number of pages, and current page number, etc., to enhance the user's perception of the page content.

Code interpretation and optimization suggestions

The code snippet provides the basic framework for implementing pagination of article lists in AnQiCMS.In practical applications, you can further customize and optimize according to the design of the website and user experience requirements.

archiveListlabel'slimitThe parameter is the key to controlling the number of articles displayed per page, and you can adjust it based on content density and user habits.categoryIdThe parameter allows you to create pagination for a list of articles in a specific category. If you want to display all categories of articles, you can specify it or configure it in the background.orderThe parameter can change the sorting method of the articles, for example, in reverse chronological order (id desc) or by view count (views desc).

In the article list, we usecategoryDetailLabels to obtain the name of the article category it belongs to, making the article information more complete. Timestamp formatting is done throughstampToDateTag implementation, you can adjust the date and time display format as needed.

About SEO, AnQiCMS static rules (help-plugin-rewrite.mdMentioned) Can ensure that pagination link generation produces a friendly URL structure, for example/category/list-1.html//category/list-2.htmlWait, this helps search engines better crawl and index your pagination content. Although the document does not directly mention setting pagination tags inrel="prev"andrel="next"However, modern search engines are already able to handle pagination content well, it is important to ensure that pagination links are crawlable and content uniqueness.

By combining these tags, AnQiCMS makes it a direct and flexible task to implement article list pagination display, helping you build a user-friendly and SEO-optimized website.


Frequently Asked Questions (FAQ)

  1. How to adjust the number of articles displayed per page?You can modify byarchiveListin the labellimitThe parameter to adjust the number of articles displayed per page. For example, if you want to display 15 articles per page, you can setlimit="10"is modified tolimit="15".

  2. How is the URL structure of pagination links determined?The pagination link URL structure is mainly determined by the 'pseudo-static rules' setting in the AnQiCMS backend.The system provides multiple preset modes, such as "numeric mode" or "categorized naming mode", and you can also customize the rules.In these rules, it usually includes a{page}Use variables to represent the page number. Make sure your pseudo-static rules are correctly configured to generate friendly pagination URLs.

  3. Does the pagination feature support SEO optimization?Yes, AnQiCMS's pagination feature is SEO-friendly.The system supports pagination by generating clear, SEO-friendly static URLs.This means that each page of content has a unique URL, which is convenient for search engine indexing.Although modern search engines have become more intelligent in handling pagination content, they no longer require itrel="prev/next"But the static URL structure of AnQiCMS is beneficial for SEO, ensuring the visibility and accessibility of content.

Related articles

How to filter and display the article list according to a specified category ID?

As an experienced CMS website operation person, I know the importance of content organization and display for user experience and SEO.In daily work, we often need to filter and display article lists according to specific categories so that readers can quickly find the content they are interested in.Today, I will elaborate on how to flexibly and efficiently filter and display article lists in AnQiCMS according to specified category IDs.The categorization of content is the foundation for the effective operation of a website.

2025-11-06

How to loop and display the latest 10 articles in the template?

As an experienced CMS website operation personnel, I fully understand the core position of content in website operation.Dynamically displaying the latest content can not only improve the user experience, but also effectively increase the activity of the website and the frequency of search engine crawling.Below, I will elaborate on how to loop and display the latest 10 article lists in the AnQiCMS template.

2025-11-06

How to get the title, content, and link of the current page document?

As an experienced website operator who deeply understands the operation of AnQiCMS, I know that the accuracy and efficiency of obtaining the current page content are crucial for the daily management and optimization of the website.AnQiCMS provides intuitive and powerful template tags, allowing us to easily extract the required document title, specific content, and standard link of the current loaded page.This not only helps us to have fine control over the front-end display, but also provides a solid foundation for SEO optimization.### Get the document title of the current page The document title of the current page usually has two levels of meaning

2025-11-06

What types of custom fields does Anqi CMS support? For example, 'Single line'

As an experienced website operator for AnQiCMS, I am well aware of the importance of the flexibility of the content management system, especially the custom field function, which can greatly meet the personalized needs of content structure and display in different business scenarios.AnQiCMS provides quite comprehensive support in this aspect, allowing us to build rich content types according to our actual needs.One of the core strengths of AnQiCMS is its flexible content model.This means that the system not only provides preset content types such as articles and products, but also gives us the power to create or modify content models according to our business characteristics

2025-11-06

How to obtain the global system configuration information such as website name, Logo, etc?

As a website operator proficient in AnQi CMS content management, publishing, and optimization, I fully understand the importance of obtaining global website configuration information for website construction and daily maintenance.This information constitutes the basic framework of the website, including brand identification, contact information, SEO metadata, etc., ensuring the uniformity, professionalism, and maintainability of the website.In Anqi CMS, obtaining these global system configuration information is intuitive and flexible, mainly achieved through built-in template tags.

2025-11-06

How to display first and second level menus and their links in the website's main navigation?

As an experienced website operator, I am well aware of the importance of a clear and intuitive navigation system for website user experience and content discovery.AnQiCMS (AnQiCMS) with its flexible content management features, allows us to easily build navigation structures that meet various business needs.Today, I will explain in detail how to cleverly set up and display the first and second-level menus and their links in the main navigation of the website based on the powerful functions of AnQiCMS.

2025-11-06

How to dynamically generate the breadcrumb navigation path of the current page?

As an expert who deeply understands the operation of AnQiCMS, I know that a clear and easy-to-use navigation system is crucial for both website visitors and search engines.Breadcrumb Navigation is an effective tool that improves user experience and website SEO performance.It can directly display the user's current position in the website structure, helping them easily backtrack, and also provide clues for search engines about the website's hierarchical structure.

2025-11-06

How to get the title and link of the previous and next articles of the current article?

As an experienced website operator familiar with AnQi CMS, I am well aware of the importance of article navigation in content management for improving user experience and optimizing website structure.When a reader is browsing an article meticulously crafted, if they can conveniently jump to the previous and next related or sequential articles, it not only extends the user's stay on the website, increases the page views, but also conveys a better internal link structure to search engines, thereby helping to improve the website's SEO performance.The AnQi CMS provides simple and powerful template tags

2025-11-06