How does the `archiveList` tag control the display quantity, sorting method, and pagination logic of the document list?

Calendar 👁️ 61

In AnQi CMS,archiveListLabels are undoubtedly the core tool for content display, providing great flexibility and control for the website's content list. Whether you want to display the latest articles on the homepage or implement complex filtering and pagination on the category page,archiveListCan help us accurately present content through its rich parameter configuration.Next, let's delve into how to use this tag to control the display quantity, sorting method, and implement exquisite pagination logic for the document list.

Control the number of documents displayed:limitFlexible use of parameters

When building a website page, we often need to control the length of the content list.For example, on the homepage of the website, you may only want to display the latest 5 articles;In the sidebar, maybe just show the top 10 products.archiveListTag throughlimitThe parameters have given us the ability to accurately control the display quantity.

The most common usage is to specify a number directly, indicating the number of documents to retrieve. For example, if you want to display the most recent 8 articles at a certain location:

{% archiveList latestArticles with type="list" limit="8" %}
    {% for item in latestArticles %}
        <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
    {% empty %}
        <li>暂无文章可显示。</li>
    {% endfor %}
{% endarchiveList %}

here,limit="8"It ensured that the list only displays a maximum of 8 articles.

limitThe parameter also supports a more advanced "offset" mode, which starts from a certain position in the result set and then retrieves a specified number of documents.This is very useful for the scenario where you need to skip the previous content (such as after the headline recommendation and display the normal list)Its format is"起始偏移量,获取数量"For example, if you want to skip the first 2 articles and display 5 articles starting from the 3rd one:

{% archiveList featuredArticles with type="list" limit="2,5" %}
    {% for item in featuredArticles %}
        <li><a href="{{ item.Link }}">{{ item.Title }}</a> - 从第三篇开始的第{{ forloop.Counter }}篇</li>
    {% empty %}
        <li>暂无文章可显示。</li>
    {% endfor %}
{% endarchiveList %}

This configuration makes content display more refined, meeting various layout needs.

Customize content sorting method:orderParameter strategy selection

The presentation order of content is crucial for user experience and information delivery.archiveListTag throughorderParameters allow you to flexibly define the sorting method of the document to highlight the most important information.

orderThe parameter accepts a string containing the field to be sorted and the sorting direction (ascfor ascending,descfor descending.). Common sorting fields include:

  • id desc: Arrange documents in descending order by document ID, which usually means they are displayed from the most recent to the oldest.
  • views desc:The documents are sorted in descending order of page views, which helps us show the most popular or hottest content.
  • sort desc: Sort by the custom sorting field in descending order. If the manual sorting weight is set for the document in the background, this option will be very practical.

For example, if you want to display the top 5 articles with the highest reading volume in the sidebar:

<div class="sidebar-hot-articles">
    <h3>热门文章</h3>
    <ul>
    {% archiveList hotArticles with type="list" order="views desc" limit="5" %}
        {% for item in hotArticles %}
            <li><a href="{{ item.Link }}">{{ item.Title }} <small>({{ item.Views }} 阅读)</small></a></li>
        {% empty %}
            <li>暂无热门文章。</li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

And if you want to display the latest content on the category page, you can use it like this:

<div class="category-new-list">
    <h2>最新发布</h2>
    <ul>
    {% archiveList newArrivals with type="list" order="id desc" limit="10" %}
        {% for item in newArrivals %}
            <li><a href="{{ item.Link }}">{{ item.Title }}</a> - 发布于 {{ stampToDate(item.CreatedTime, "2006-01-02") }}</li>
        {% empty %}
            <li>此分类暂无最新文章。</li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

By cleverly pairingorderParameters, we can ensure that the content of the website is always presented to the user in the most reasonable and attractive way.

Implement content pagination logic:type="page"withpaginationTag联动

When the amount of content on a website is large, pagination is an essential feature that can effectively improve page loading speed and user browsing experience. In Anqi CMS, implementing pagination requiresarchiveListwith the tag andpaginationThe clever combination of tags.

First, inarchiveListIn the tags, we need to shift.typethe parameter to"page"This will tell the system that we want to get a paged document list, not a fixed-length list. At this point,limitThe parameter will be used to define the number of documents displayed per page.

For example, to display 10 articles per page on the article list page:

{% archiveList articles with type="page" limit="10" %}
    <div class="article-list">
        {% for item in articles %}
            <article>
                <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
                <p>{{ item.Description }}</p>
                <span>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
            </article>
        {% empty %}
            <p>此列表暂无内容。</p>
        {% endfor %}
    </div>
{% endarchiveList %}

Just setting this up, the page will not automatically display page navigation. At this point, you needpaginationThe tag has appeared.paginationthe tag to readarchiveListthe prepared pagination data and generate the actual page navigation links. It is usually placedarchiveListBelow the label, and wrapped in a{% pagination pages with show="5" %}...{% endpagination %}structure. Among them,show="5"it means that up to 5 page number buttons are displayed (such as 1, 2, 3, 4, 5).

An example of a complete pagination list and page navigation is as follows:

{# 假设这是文章列表页模板 #}
<div class="main-content">
    {% archiveList articles with type="page" limit="10" order="id desc" %}
        <div class="article-list">
            {% for item in articles %}
                <article>
                    <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
                    <p>{{ item.Description }}</p>
                    <span>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                </article>
            {% empty %}
                <p>此列表暂无内容。</p>
            {% endfor %}
        </div>

        {# 分页导航区域 #}
        <div class="pagination-nav">
            {% pagination pages with show="5" %}
                <ul>
                    {# 首页按钮 #}
                    <li {% if pages.FirstPage.IsCurrent %}class="active"{% endif %}><a href="{{ pages.FirstPage.Link }}">{{ pages.FirstPage.Name }}</a></li>
                    
                    {# 上一页按钮 #}
                    {% if pages.PrevPage %}
                        <li><a href="{{ pages.PrevPage.Link }}">{{ pages.PrevPage.Name }}</a></li>
                    {% endif %}

                    {# 中间页码按钮组 #}
                    {% for pageItem in pages.Pages %}
                        <li {% if pageItem.IsCurrent %}class="active"{% endif %}><a href="{{ pageItem.Link }}">{{ pageItem.Name }}</a></li>
                    {% endfor %}

                    {# 下一页按钮 #}
                    {% if pages.NextPage %}
                        <li><a href="{{ pages.NextPage.Link }}">{{ pages.NextPage.Name }}</a></li>
                    {% endif %}
                    
                    {# 尾页按钮 #}
                    <li {% if pages.LastPage.IsCurrent %}class="active"{% endif %}><a href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a></li>
                    
                    <li class="info">总数:{{ pages.TotalItems }}条,共:{{ pages.TotalPages }}页,当前第{{ pages.CurrentPage }}页</li>
                </ul>
            {% endpagination %}
        </div>
    {% endarchiveList %}
</div>

In this example,pagesThe variable contains all information related to pagination, such as the current page number (pages.CurrentPage), total number of pages (pages.TotalPages), and previous page link (pages.PrevPage.Link)and a series of middle page number buttons(pages.Pages)。By traversingpages.Pages,we can generate a complete page navigation bar.

It is worth mentioning that whentype="page"enabled,archiveListWill automatically recognize URLs inqParameter

Related articles

How to use the various tags built into AnQiCMS to retrieve and display the system information, content list, and details of the website?

How to efficiently display various information when building and managing a website is the key to user experience and operational efficiency.AnQiCMS With its flexible and powerful template tag system, enables content creators and website operators to easily control the acquisition, display, and personalized customization of website content without a deep programming background.This article will delve into the rich tags built into AnQiCMS, showing you how to cleverly use them to retrieve and display the system information, content list, and diverse content of detail pages of the website.Understanding AnQiCMS

2025-11-08

How to customize independent display templates for single pages such as 'About Us' to meet specific display requirements?

In Anqi CMS, in order to make single pages like "About Us" and "Contact Us" have unique display effects, rather than following the unified page layout of the website, we can customize independent display templates for them.This customized capability is a reflection of the flexibility of Anqi CMS, which can help us better shape our brand image, or provide a more suitable display form for specific content.### Overview of AnQi CMS Template Mechanism The AnQi CMS template system is designed to be very intuitive and powerful, based on syntax similar to the Django template engine, which separates the presentation of content from logical control.

2025-11-08

How does AnQiCMS's flat file organization pattern simplify template management and optimize the content display process?

In website operation, template management is a key link that balances efficiency and experience.A well-designed, easy-to-maintain template system that can greatly enhance the speed of website content publishing and the flexibility of page updates.AnQiCMS provides unique solutions in this field, especially its 'flat file organization mode', which brings practical convenience to users in simplifying template management and optimizing the content display process.### Say goodbye to layered nesting: The charm of AnQiCMS flat file organization In many traditional content management systems, template files are often buried deep in a multi-level directory structure

2025-11-08

How to specify a specific display template for the homepage, detail page, list page, etc. of the AnQiCMS website?

When building a website, we often need to assign unique appearances and functions to different page types, such as the grand layout of the homepage, the immersive reading experience of the article detail page, or the filtering and display of the product list page.AnQiCMS provides a flexible mechanism that allows users to easily specify and manage display templates for each page of the website.This has greatly enhanced the customization of the website, as well as greatly optimized the user experience and content presentation efficiency. The template files of AnQiCMS website are uniformly stored in the `/template` directory. Usually

2025-11-08

How to retrieve and display the detailed information of a single document, including its custom fields, using the `archiveDetail` tag?

In a content management system, effectively displaying the detailed information of a single document is one of the core requirements.Whether it is news articles, product introductions, or service descriptions, users always hope to have a direct and comprehensive understanding of the specific content of each item.AnQiCMS provides a powerful `archiveDetail` tag, allowing you to easily retrieve and display all information of a single document, including your custom exclusive fields.### Retrieve the core information of the document: `archiveDetail`

2025-11-08

How are the `categoryList` and `categoryDetail` tags used to build and display the hierarchical structure of the website?

In Anqi CMS, the classification hierarchy of the website is the core of content organization, which not only affects the user's browsing experience, but is also an important link in search engine optimization.To effectively build and display these classification structures, we mainly rely on two powerful template tags: `categoryList` and `categoryDetail`.They work together, allowing you to flexibly present clear and organized content categories on the website front-end.### Build the category list: `categoryList` tag `categoryList`

2025-11-08

How to manage and display independent single-page content for the `pageList` and `pageDetail` tags?

In website operation, in addition to dynamically updated articles or product lists, we often need to display some relatively fixed and independent content pages, such as "About Us", "Contact Information", "Privacy Policy" or "Service Introduction" and so on.These pages are usually called "single-page content". AnQiCMS provides us with powerful and flexible tools for managing and displaying these pages, especially the core tags `pageList` and `pageDetail`.### Single Page Content: The Foundation of a Website Single page content is an indispensable part of a website

2025-11-08

How to implement content aggregation and thematic display based on `tagList` and `tagDetail` tags?

In content management and website operations, how to efficiently organize and display content is the key to improving user experience and SEO performance.AnQiCMS provides powerful tag features, with the `tagList` and `tagDetail` template tags, it is easy to implement content aggregation based on tags and thematic display, bringing more flexible classification and richer navigation experience to the website.### The role of tags in content aggregation Tags are an important way to organize content in a content management system

2025-11-08