As an experienced website operations expert, I have accumulated rich experience in the content management practice of AnQiCMS.I am well aware that when facing the powerful template tag system of AnQiCMS, how to skillfully combine them to achieve the expected content display effect is a challenge that many operators and developers may encounter.categoryListnestedarchiveListhow to properly handlearchiveListpagination problem?

pagination困境:understanding the core logic in nested scenarios

First, let's clarify what AnQiCMS is aboutcategoryListandarchiveListThe function of these two core tags.categoryListTags are used to iterate over and display the classification information of the website, such as listing all product categories on the homepage, or displaying the article classification tree in the sidebar. AndarchiveListTags are used to retrieve and display a list of documents (articles, products, etc.). When we need to display related documents under a category, it is natural to nestarchiveListincategoryListthe loop.

Where are the challenges of pagination? In AnQiCMSarchiveListTags can be set bytype="page"Parameters to enable pagination and work withpaginationCreate pagination links. However, the key here is that the pagination parameters in the URL (such as?page=2) are usually targetedat the single list of the main content area of the entire pagefor control.

Imagine if you displayed multiple categories on a page, each with onearchiveListto display their articles. At this point, if eacharchiveListTry to perform "pagination", in the URL of?page=XWhat parameter should control which category of document list jumps to the second page?This is contradictory and cannot be unified in logic.A page usually only has one leading pagination list.

Therefore, when you try tocategoryListLoop to set each nestedarchiveListAll to settype="page"And when you expect them to be independently paginated, you will find that this method cannot achieve the effect you might imagine of 'each category has its own independent pagination control'.

Solution one: Display in nested scenarios in a 'summary-style'

In most cases, it willarchiveListincategoryListIn order to display on the homepage, category overview page, or sidebar, etc., in order tosummary or selectedDisplay a few of the latest or most popular documents in each category.Under such 'summary' display scenarios, we usually do not need to provide complete pagination functionality for each category of document list.

The correct approach is to let nestedarchiveListUsetype="list"parameters cooperatelimitto limit the number of documents displayed. In this way, each category will show its latest few articles without the inconvenience of pagination.

For example, suppose you want to display several main categories on the homepage, with the latest 5 articles displayed under each category:

{% categoryList categories with moduleId="1" parentId="0" %}
<div class="category-sections">
    {% for category in categories %}
    <div class="category-card">
        <h3><a href="{{ category.Link }}">{{ category.Title }}</a></h3>
        <ul>
            {# 在分类列表内部,我们通常只展示每个分类的最新几篇文章,而不是分页显示所有文章 #}
            {% archiveList archives with type="list" categoryId=category.Id limit="5" order="id desc" %}
            {% for article in archives %}
            <li>
                <a href="{{ article.Link }}">{{ article.Title }}</a>
                <span class="publish-date">{{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
            </li>
            {% empty %}
            <li>该分类暂无文章。</li>
            {% endfor %}
            {% endarchiveList %}
            <a href="{{ category.Link }}" class="more-link">查看更多 {{ category.Title }} 的文章 &raquo;</a>
        </ul>
    </div>
    {% endfor %}
</div>
{% endcategoryList %}

In this code block,archiveListExplicitly usedtype="list"andlimit="5"Ensure that each category only displays a fixed number of documents. If a user wants to view all the documents in a category and browse them by pages, they will click on the category title or the "View More" link and jump to the category'sExclusive List Page.

Solution Two: Full-page pagination of the exclusive list page

When the user clicks to enter a specific category page (for exampleyourdomain.com/category/newsThis page is the exclusive list page of this category. On this page, full-page pagination of documents is logical and meets user expectations.

In the template of the exclusive list page (usually{模型table}/list.htmlor{模型table}/list-{分类id}.html), you can usearchiveListtags and settype="page", along withpaginationTag to generate pagination. AnQiCMS is very intelligent, it will automatically identify the current category ID according to the current page URL, so you usually do not need to explicitly specify inarchiveListto specifycategoryId.

This is a dedicated list page template example:

List of articles of {{ currentCategory.Title }}

{% archiveList articles with type=“page” limit=“10” %} {# categoryId will automatically be obtained from the current page #}

{% for article in articles %}
<div class="article-item">
    <h3><a href="{{ article.Link }}">{{ article.Title }}</a></h3>
    <p class="description">{{ article.Description }}</p>
    <span class="meta-info">发布日期: {{ stampToDate(article.CreatedTime, "2006-01-02") }} | 浏览量: {{ article.Views }}</span>
</div>
{% empty %}
<p>该分类下暂无文章。</p>
{% endfor %}

{% endarchiveList %}

{# Pagination Control #} {% pagination pages with show=“5” %}

<nav class="pagination-controls">
    {% if pages.FirstPage %}
        <a href="{{ pages.FirstPage.Link }}" class="page-link">首页</a>
    {% endif %}
    {% if pages.PrevPage %}
        <a href="{{ pages.PrevPage.Link }}" class="page-link">上一页</a>
    {% endif %}