How to retrieve and display the article list in the template and control the number of articles displayed per page?

Calendar 👁️ 72

When using AnQiCMS to manage website content, it is an everyday need for operators to flexibly display article lists on the front-end page.Whether it is the latest dynamic on the homepage, the collection of articles under the category page, or the content aggregation page with pagination functionality, AnQiCMS provides powerful and easy-to-use template tags to help us achieve these functions.Today, let's delve into how to efficiently retrieve and display article lists in the AnQiCMS template and precisely control the number of articles displayed per page.

Core:archiveListTag, the 'scheduler' of content display

The core tool for displaying article lists in AnQiCMS templates isarchiveListThe tag is like an intelligent content scheduler that can filter out the target content from a large number of articles according to the conditions we set and present it in the way we expect.

We start with the most basic usage. If you just want to display a certain number of articles on the page, such as the latest 5 articles, you can use it like thisarchiveListTags:

{% archiveList archives with type="list" limit="5" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <p>{{item.Description}}</p>
            <div>
                <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>阅读量:{{item.Views}}</span>
            </div>
        </a>
    </li>
    {% else %}
    <li>暂时没有相关文章。</li>
    {% endfor %}
{% endarchiveList %}

In this code block,archiveListTag throughtype="list"Specified the list type as a fixed list, andlimit="5"then explicitly tells the system to only retrieve the latest 5 articles.archivesis the variable name we give to the retrieved article list, in subsequentforIn the loop, we can display the detailed information of each article byitem.Title/item.LinkAccess the title, link, and other information of each article in this way.stampToDateThe tag is used to format the timestamp of the article into a readable date format.

Advanced:type="page"withpaginationTag to implement pagination of article lists

When your content is large and requires users to click on page numbers to browse more articles,archiveListwith the tag andpaginationthe combination of tags is particularly important.

first, archiveListtags need to betypethe parameter to"page"This will inform the system that the article list we expect to get is for pagination display, and the system will automatically handle the current page number and the total number of articles.

Next, we need to introducepaginationTags to generate page navigation.paginationThe label will be based onarchiveListProcessed pagination data, automatically generates 'Home', 'Previous page', 'Next page', and specific page number links.

Let us understand how they work together through a complete example:

{# 假设这是一个文章列表页,通过URL参数可传递分类ID或搜索关键词 #}

<div class="article-list-container">
    {% archiveList archives with type="page" limit="10" moduleId="1" %} {# 获取文章模型下每页10篇文章,准备分页 #}
        {% for item in archives %}
        <article class="article-item">
            <a href="{{item.Link}}">
                {% if item.Thumb %}
                <div class="article-thumb">
                    <img src="{{item.Thumb}}" alt="{{item.Title}}">
                </div>
                {% endif %}
                <div class="article-info">
                    <h3>{{item.Title}}</h3>
                    <p class="article-description">{{item.Description}}</p>
                    <div class="article-meta">
                        <span class="category-name">分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                        <span class="publish-date">发布于:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                        <span class="views">浏览:{{item.Views}}</span>
                    </div>
                </div>
            </a>
        </article>
        {% else %}
        <p class="no-content">当前分类下没有文章。</p>
        {% endfor %}
    {% endarchiveList %}
</div>

{# 分页导航区域 #}
<div class="pagination-nav">
    {% pagination pages with show="5" %} {# 显示最多5个页码链接 #}
        {% if pages.TotalPages > 1 %} {# 只有当总页数大于1时才显示分页 #}
        <ul>
            {% if pages.FirstPage %}
            <li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a></li>
            {% endif %}

            {% if pages.PrevPage %}
            <li><a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a></li>
            {% endif %}

            {% for pageItem in pages.Pages %}
            <li class="{% if pageItem.IsCurrent %}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 %}

            {% if pages.LastPage %}
            <li class="{% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a></li>
            {% endif %}
        </ul>
        <p>总共 {{pages.TotalItems}} 篇文章,当前第 {{pages.CurrentPage}} / {{pages.TotalPages}} 页。</p>
        {% endif %}
    {% endpagination %}
</div>

In this example:

  • archiveListlabel'slimit="10"Defined to display 10 articles per page.
  • moduleId="1"Ensure that we only retrieve the content with ID 1 (usually the article model).
  • pagination pages with show="5"Instruct the system to generate page navigation,pagesis the variable name we define for pagination data,show="5"This indicates that at most 5 page number links will be displayed in the middle section, and the excess part will be automatically omitted.
  • InpaginationWe make use of it within the tagpages.FirstPage/pages.PrevPage/pages.Pages(This is an array containing the middle page numbers,)pages.NextPageandpages.LastPageproperties, flexibly building a complete page navigation structure.pageItem.IsCurrentcan help us highlight the current page we are on.

By this combination, we can very conveniently create a fully functional, user-friendly article pagination list.

Enrich the article list:archiveListCommon parameters of the tag

In addition to controlling the display quantity and pagination,archiveListTags also support various parameters for refined filtering and sorting of articles, making your content display more diverse and accurate:

  • moduleId:When your AnQiCMS website has various content models such as articles and products, you canmoduleId="1"(article model ID) ormoduleId="2"(Product Model ID) to specify the list of articles under a specific model.
  • categoryId:Want to only display articles under a specific category,categoryId="10"(Category ID 10 can be used). You can also separate multiple category IDs with commas, for example,categoryId="1,3,5". If you willcategoryIdis set to"0"This means not to automatically read the current page category ID, which is very useful when you need to get the hot articles of the entire site.
  • order:The sorting method of the content can also be flexibly controlled.order="id desc"Indicates sorting by the latest release (ID descending),order="views desc"Indicates sorting by views from high to low,order="sort desc"Then, it is sorted according to the sorting value manually set in the background.
  • flag:By coordinating the recommended attributes of the background articles (such as头条[h], recommendation[c]), you canflag="h"to obtain a list of articles with the headline attribute.
  • q:on the search results page,qParameter

Related articles

How does AnQiCMS implement the switching and display of multilingual content to enhance the international user experience?

In today's globalized digital world, a website that can present its content in multiple languages undoubtedly can greatly expand its user base and significantly enhance the user experience.AnQiCMS as a powerful content management system, fully considers the needs of international operation, and provides a flexible and efficient mechanism to switch and display multilingual content.### Why is multilingual content so important? Imagine a user from Japan visiting your website. If they can read product descriptions or service instructions in their native language, their trust and engagement will immediately increase

2025-11-08

How to utilize the flexible content model of AnQiCMS to customize unique display fields for different types of content (such as articles, products)?

AnQiCMS, this is a content management system driven by the Go language, which performs very well in content management, especially its flexible content model function.As website operators, we often need to publish various types of content, such as detailed product introductions, professional technical articles, vivid case studies, and so on.Each content has its unique display requirements and information structure.Traditional content management systems may require cumbersome secondary development to meet these differences, but AnQiCMS's flexible content model is exactly born to solve this pain point, allowing us to easily customize

2025-11-08

How to correctly call and display the title and content of the article in the template?

When using AnQiCMS to build and manage websites, the title and content of articles are core elements. Their correct invocation and display are directly related to the visual presentation, user experience, and search engine optimization of the website.Understanding how to efficiently and accurately handle this information in the AnQiCMS template is the key to website content operation and template customization.AnQiCMS's template system adopts syntax similar to the Django template engine, which provides great flexibility and customizability for content display.In the template, you will find that variables are usually enclosed in double curly braces

2025-11-08

What template types does AnQiCMS support, and how do you choose the most suitable display mode for the website (adaptive, code adaptation, PC + mobile end)?

AnQiCMS as an efficient and customizable content management system provides a variety of flexible modes for displaying website content to meet the diverse needs of different users.Understanding these template types and their applicable scenarios is crucial for building a website with a good user experience, easy management, and search engine optimization.AnQiCMS provides three main template types for users to meet the display needs of different websites.They are adaptive templates, code adaptation templates, and independent PC + mobile site templates.Each pattern has its unique characteristics and applicable scenarios

2025-11-08

How to customize the display layout of the article detail page, including images, descriptions, and custom parameters

In AnQi CMS, the display layout of the article detail page has extremely high flexibility, whether it is to show the core content of the article, beautiful pictures, or customized business parameters, the system provides an intuitive and powerful way to help you meet your personalized needs.This is due to the template engine of AnQiCMS based on Django-like syntax, which separates content from design, allowing even users without a strong programming background to adjust layouts through simple tags.### Understanding the Composition of Article Detail Page In AnQiCMS, articles (or products

2025-11-08

How to loop through and output the article list in AnQiCMS template?

AnQiCMS provides a powerful and flexible template system for website content management, among which, the loop traversal and output of the article list is an indispensable core function for building a dynamic website.Whether you need to display the latest articles, category lists, or implement advanced filtering and pagination, AnQiCMS template tags can help you complete it efficiently.

2025-11-08

How to get the current loop item index or remaining item count in an article?

When using AnQi CMS for website content display, we often need to finely control each item in the list.This may include adding numbers to articles, highlighting the first or last item in a list, or applying different styles based on the position of the item in the list.The AnQi CMS template system uses a syntax similar to the Django template engine, where the key to handling list loops is the `for` loop tag.

2025-11-08

How to implement reverse or custom sorting output of AnQiCMS's `for` loop?

The order of website content listings is crucial for user experience and information delivery.Whether it is news updates, product displays, or article archives, flexibly controlling the output order of lists is a common demand in website operation.AnQiCMS provides a powerful and easy-to-use template engine, allowing us to easily control the arrangement of lists, including reverse order and sorting by specific rules.### AnQiCMS Template Engine Basics The AnQiCMS template system adopts the syntax style of the Django template engine, using concise tags and variable declarations

2025-11-08