How to display the article list on the AnQiCMS website and support sorting by publish time in descending order?

Calendar 👁️ 67

When operating a website, efficiently displaying the content list is a key factor in attracting visitors and improving user experience.For friends who use AnQiCMS, the system provides very flexible and powerful template functions that can easily achieve various complex content display requirements.Today, let's discuss how to display the article list on the AnQiCMS website, and ensure that the articles are arranged in order from the most recent to the oldest, while also supporting friendly pagination features.

The AnQiCMS template system has borrowed the syntax of the Django template engine, making it very easy for content developers to get started. You will see tags (with{%and%}Packages are used to control logic, while variables (with{{and}}Packages are used to output data. Master these basic syntaxes, and you can easily handle the content display of AnQiCMS.

Understand the core tags:archiveListSorted by time

The most core tags to display the article list in AnQiCMS are:archiveList. It is specifically used to retrieve document data from websites, including articles, products, etc. This tag has a rich set of parameters that can help us accurately filter, sort, and display content.

To implement descending order sorting by publish time, we need to pay attention toarchiveListlabel'sorderthe parameters. AnQiCMS internally stores the publish time field of each article, usuallyCreatedTime. Therefore, it is set toorder="CreatedTime desc"can achieve the effect we want,descmeans descending. If we want the article to support pagination, we also need totypethe parameter topage.

In addition, sinceCreatedTimeThe field is usually a timestamp, in order to display it in a date format we are familiar with, we also need to usestampToDatetemplate functions for formatting.

Step 1: Prepare the template file

Firstly, you need to enter the template file directory of AnQiCMS. Usually, the article list is stored in a similartemplate/your_theme_name/article/list.htmlortemplate/your_theme_name/list.htmlThe position. If you are creating a new list page, you cantemplate/your_theme_name/create a new HTML file underblog_list.html.

Second step: usearchiveListTags retrieve article data

In your template file, we will usearchiveListTags to pull article data. Here, we specify the retrieval of the article model (usuallymoduleId="1"Representing the article model, please refer to your backend configuration for details) and list all articles in descending order of publication time.

{% archiveList archives with moduleId="1" type="page" order="CreatedTime desc" limit="10" %}
    {# 循环体将在第三步填充 #}
{% endarchiveList %}

In this code block:

  • archivesThis is a variable name defined to store the article list data obtained.
  • moduleId="1"Instruct the system to retrieve the content under the article model.
  • type="page"Enable pagination mode, which prepares for adding pagination navigation later.
  • order="CreatedTime desc"It is the key to sorting by published time in descending order.
  • limit="10"It means that 10 articles are displayed per page.

Step 3: Loop through the article content and format the time

After obtaining the article data, we need toforLoop througharchivesvariables to display the title, link, and publishing time of each article.

{% archiveList archives with moduleId="1" type="page" order="CreatedTime desc" limit="10" %}
    {% for item in archives %}
    <article class="article-item">
        <h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
        <div class="article-meta">
            <span>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}</span>
            <span>浏览量:{{ item.Views }}</span>
            {# 您还可以显示文章简介、分类等信息 #}
            <p>{{ item.Description }}</p>
        </div>
    </article>
    {% empty %}
    <p>抱歉,目前没有找到任何文章。</p>
    {% endfor %}
{% endarchiveList %}

Here:

  • {% for item in archives %}Traverse the article list,itemRepresents the current article object being looped over.
  • {{ item.Link }}and{{ item.Title }}Outputted the links and titles of the articles separately.
  • {{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}UsestampToDateThe function willCreatedTimeFormat the timestamp into a readable form of “Year-Month-Day Hour:Minute”.Please note,"2006-01-02 15:04"Is a date and time formatting template unique to the Go language, representing参考时间Cannot be changed arbitrarily.
  • {% empty %}Block is a very practical feature, whenarchivesWhen the list is empty, it will display its content instead of an empty page.

Step 4: Add pagination functionality (optional but highly recommended)

If you have a large number of articles, the pagination feature will greatly enhance the user experience. AnQiCMS providespaginationtags, which can be seamlessly connected witharchiveListoftype="page"parameters.

In{% endarchiveList %}After the tag, add the following pagination code:

{# ... 文章列表循环结束 ... #}

<div class="pagination-container">
    {% pagination pages with show="5" %}
        {# 首页链接 #}
        <a class="page-link {% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
        {# 上一页链接 #}
        {% if pages.PrevPage %}
        <a class="page-link" href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
        {% endif %}
        {# 中间页码 #}
        {% for pageItem in pages.Pages %}
        <a class="page-link {% if pageItem.IsCurrent %}active{% endif %}" href="{{pageItem.Link}}">{{pageItem.Name}}</a>
        {% endfor %}
        {# 下一页链接 #}
        {% if pages.NextPage %}
        <a class="page-link" href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
        {% endif %}
        {# 尾页链接 #}
        <a class="page-link {% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
    {% endpagination %}
</div>

Here:

  • pagesIspaginationVariable automatically generated by the tag containing pagination information.

Related articles

How to safely display user-entered HTML content (such as article text) in AnQiCMS templates?

In website content operations, displaying user input information is one of the core functions, especially like the main text of articles that may contain rich formatting content.However, how to safely and accurately present these user-entered HTML content on the website while preventing potential security risks (such as cross-site scripting XSS attacks) is a problem that every website operator needs to think deeply about.AnQiCMS provides flexible and powerful tools for template design and content processing to meet this challenge.### AnQiCMS's default security mechanism: automatic escaping is the cornerstone AnQiCMS

2025-11-07

How to get and display the contact phone number and address set in the AnQiCMS template?

It is crucial to clearly and accurately display contact information in website operations to enhance user trust and promote communication and exchange.AnQiCMS provides a convenient backend setting and template calling mechanism, allowing you to easily manage and display this key information.This article will introduce in detail how to configure contact phone numbers and addresses in the AnQiCMS backend, as well as how to obtain and flexibly display this content in website templates.--- ### One, configure the contact phone number and address in the AnQiCMS backend Firstly, we need to configure in AnQiCMS

2025-11-07

How does the AnQiCMS template display the base URL address of the current website?

In website operation and template development, accurately obtaining and displaying the basic URL address of the current website is a very basic but important requirement.It is crucial to understand how to flexibly call the basic URL of the website in AnQiCMS template, whether it is for correctly loading the static resources of the website (such as CSS, JavaScript, and images), or for building dynamic internal links, or for generating Canonical URL in accordance with SEO standards.AnQiCMS as an efficient and customizable content management system, fully considers this requirement

2025-11-07

How to display the filing number and copyright information at the bottom of the AnQiCMS website?

In website operation, the information display at the bottom of the website, especially the filing number and copyright statement, is not only an embodiment of website compliance, but also an important way to convey trust and professionalism to visitors.For websites built using AnQiCMS, it is a fundamental operation to display these key information flexibly and efficiently at the bottom of the website, which is the basis for improving user experience and meeting legal and regulatory requirements.

2025-11-07

How to implement pagination for article lists in AnQiCMS templates?

Good, as an experienced website operations expert, I know that implementing pagination for the article list in AnQiCMS not only improves user experience and makes content browsing smoother, but also helps with search engine optimization, allowing website content to be indexed better.Next, I will combine the AnQiCMS template mechanism and explain in detail how to easily implement this feature.

2025-11-07

How to display the title and link of the previous and next articles on the AnQiCMS article detail page?

Managing website content in AnQiCMS and providing users with a smooth browsing experience is one of the key factors in content operation.After a user finishes reading an excellent article, they often hope to easily jump to related or consecutive content, and the "Previous" and "Next" navigation on the article detail page is an important function to meet this need.AnQiCMS provides simple and powerful template tags, allowing you to easily implement this feature on the article detail page.### Easily Achieve

2025-11-07

How to retrieve and display related article lists based on the current article in AnQiCMS template?

How to intelligently display related article lists in the AnQiCMS template?After we publish an excellent article, it is natural for us to hope that readers will continue to browse more interesting content on the website.This involves the skill of displaying the 'related articles' list at the bottom of the article detail page.A highly recommended relevant article, not only can it effectively extend the user's stay on the website, improve user experience, but also has great benefits for the website's SEO optimization and content in-depth mining.AnQiCMS (AnQiCMS) knows this and provides a very concise and efficient template tag for it

2025-11-07

How to create a multi-level navigation with secondary dropdown menus in the AnQiCMS website navigation?

In website operation, a clear and efficient navigation system is the key to user experience and an important part of search engine optimization.AnQiCMS provides flexible navigation settings, allowing website administrators to easily create and manage multi-level navigation menus, including support for secondary dropdown menus.Next, we will learn together how to achieve this goal in AnQiCMS. ### Step 1: Configure the navigation link in the background First, you need to log in to the AnQiCMS backend management interface and enter the navigation settings module.

2025-11-07