How to call and display the latest article list in AnQi CMS?

Calendar 👁️ 61

As a rich-featured and easy-to-use content management system, AnQi CMS provides great flexibility in content display.When you need to display the latest articles on your website to visitors, such as on the homepage, sidebar, or a specific topic page, Anqi CMS can help you easily achieve this requirement.

To implement the function of calling and displaying the latest article list in Anqi CMS, the key lies in flexibly using its powerful template tag system, especiallyarchiveListLabel. The Anqi CMS template engine is similar to Django, allowing you to call various data on the page using concise tag syntax.

UnderstandingarchiveListBasic usage of tags

archiveListThe tag is the core tag used by Anqi CMS to obtain article list data. Its basic structure is as follows:

{% archiveList archives with ... %}
    {% for item in archives %}
        {# 在这里显示每篇文章的具体信息 #}
    {% endfor %}
{% endarchiveList %}

Here, archivesIt is a variable name you define for the article list, and you can name it according to your preference.itemIt represents each article object in the loop, you can obtain the various properties of the article byitem.字段名.

Key parameters: How to get the "latest" article

To call and display the 'latest' articles, you need to pay attention toarchiveListSeveral key parameters of the tag:

  1. orderparameters:This is the core factor that determines the sorting method of the articles. To get the latest articles, you can setorderis set toid desc(Sorted by article ID in descending order, usually the larger the article ID, the later the release, that is, the newer) orCreatedTime desc(Sorted by article creation time in descending order). For example:order="id desc".
  2. limitparameters:Used to control the number of articles you want to display. If you want to display 5 of the latest articles on the page, you can setlimit="5".
  3. moduleIdparameters:The Anqi CMS supports multiple content models (such as articles, products, etc.).To ensure that only content of the article type is called, you need to specify the model ID of the article explicitly.1Therefore, it can be set tomoduleId="1".
  4. typeparameters:If you just want to display a simple article list without pagination, you cantypeis set tolist.

Display the article details

In{% for item in archives %}Access within the loop, you canitemVarious properties of the object are used to display the title, link, publication date, thumbnail, etc. of the article. Common properties include:

  • item.Title: Article title.
  • item.Link: Link to the article details page.
  • item.Description: Article summary.
  • item.CreatedTime: Article creation time (timestamp format, needs to be formatted).
  • item.Views: Article views.
  • item.Thumb: Article thumbnail address.
  • item.Logo: Article cover first image address.

ForCreatedTimeSuch a timestamp field, Anqi CMS provides a convenientstampToDatefunction to format the display. For example,{{stampToDate(item.CreatedTime, "2006-01-02")}}the timestamp will be formatted as a date in the format of “year-month-date”.

Actual operation example: Call and display 5 of the latest articles

Suppose you want to display 5 of the latest articles at a location on the website, including titles, publication dates, and article links, and display thumbnails if available. You can place the following code snippet in your AnQi CMS template file (for exampleindex.htmlorpartial/aside.htmlIn:

<div class="latest-articles-list">
    <h3>最新文章</h3>
    <ul>
        {% archiveList archives with moduleId="1" order="id desc" limit="5" type="list" %}
            {% for item in archives %}
                <li>
                    <a href="{{ item.Link }}">
                        {% if item.Thumb %}
                            <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-thumb">
                        {% else %}
                            {# 如果没有缩略图,可以显示一个默认图片或省略图片区域 #}
                            <img src="/public/static/images/default-thumb.webp" alt="默认缩略图" class="article-thumb">
                        {% endif %}
                        <div class="article-info">
                            <h4>{{ item.Title }}</h4>
                            <p class="article-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</p>
                        </div>
                    </a>
                </li>
            {% empty %}
                <li>暂无最新文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

Code analysis:

  • {% archiveList archives with moduleId="1" order="id desc" limit="5" type="list" %}:
    • archives:Store the list of articles retrieved to a namearchives.
    • moduleId="1":Specify the content under the article model (ID usually 1).
    • order="id desc":In descending order by article ID, make sure to get the latest published article.
    • limit="5":Limit to displaying only 5 articles.
    • type="list":Get in list form, do not handle pagination.
  • {% for item in archives %}: Loop through.archivesEach article object in the variable.
  • {% if item.Thumb %}: Determine whether the current article has a thumbnail. If it does, then display it.
  • <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-thumb">: Display the thumbnail,altProperty helps SEO and user experience.
  • <h4>{{ item.Title }}</h4>Display article title.
  • <p class="article-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</p>Format and display the article publish date.
  • {% empty %}: It is a very practical tag, whenarchivesIf the list is empty, it will display<li>暂无最新文章。</li>to avoid blank pages on the page.

By following these steps and example code, you can flexibly call and display the latest article list in Anqi CMS.The strength of AnQi CMS lies in its customizable template system, allowing you to freely combine and display content according to the actual needs of your website.


Frequently Asked Questions (FAQ)

1. How to display the latest articles under a specific category only?

You canarchiveListthe tag withcategoryIdSpecify the category ID. For example, to display articles of category ID10you can write like this:{% archiveList archives with moduleId="1" categoryId="10" order="id desc" limit="5" type="list" %}You can find the corresponding category ID in the "Content Management" -> "Document Category" in the background.

2. How to implement pagination for the latest article list?

If the latest article list is long, you may want to paginate. This requires thatarchiveListlabel'stypethe parameter topage,and cooperatepaginationLabel usage. For example:{% archiveList archives with moduleId="1" order="id desc" limit="10" type="page" %}(After the loop){% pagination pages with show="5" %}...{% endpagination %}Specific.paginationLabel usage, it is recommended to refer to the 'Template Tags and Usage Methods' document of Anqi CMS, which contains detailed pagination code examples.

3.order="id desc"andorder="CreatedTime desc"What is the difference when getting the latest articles?

order="id desc"It is sorted in descending order based on the unique identifier (ID) of the article in the database.In most cases, the article ID is incremental, so the larger the ID, the later the publication time, thus achieving the effect of obtaining the latest articles.order="CreatedTime desc"It is directly sorted in descending order according to the article creation time field.This is a more precise 'latest' definition in theory.In practice, both effects are often very similar. You can choose one based on personal preference or specific needs.CreatedTime desc.

Related articles

How can I obtain and display the links and titles of the previous/next document on the document detail page?

In website content operation, adding "Previous" and "Next" navigation to the document detail page is a common strategy to improve user experience, guide users to deeply browse, and optimize the internal links of the website.AnQiCMS is a content management system that fully considers these needs and provides intuitive and simple template tags, allowing you to easily achieve this function.### The advantage of AnQiCMS implementing the "Previous/Next" navigation AnQiCMS's template system is designed ingeniously, adopting syntax similar to the Django template engine, by

2025-11-08

How to implement sorting display of content in a document list by the latest, the hottest, and other methods?

When managing website content, how to effectively organize and display a list of documents so that it meets user habits and highlights the key points is a very critical link.AnQiCMS (AnQiCMS) provides flexible and powerful features that allow you to easily implement various sorting and filtering of document content, whether it is by the latest release, most popular, or other customized methods.In AnqiCMS, the flexible display of the document list is mainly realized through the powerful `archiveList` template tag.

2025-11-08

How to customize the prompt information page displayed to users when the website is closed?

When a website needs to be maintained, upgraded, or temporarily suspended, displaying a friendly prompt page to visitors instead of a cold error message is crucial for improving user experience and maintaining brand image.AnQiCMS (AnQiCMS) is well-versed in this, providing a flexible and convenient way for you to easily customize the prompt information page when the website is closed. ### The shutdown handling mechanism of AnQi CMS AnQi CMS is built with website status management functions, allowing you to control the visibility of your website to the outside world with one click.In the background "Global Function Settings"

2025-11-08

How to set up the website logo and filing number and ensure they are displayed correctly on the page?

## SecureCMS: Website Logo and Filing Number Setup and Display Guide A professional and compliant website cannot do without a clear brand identity (Logo) and necessary legal information (such as filing number).The Anqi CMS provides a convenient way to manage these important website elements and ensures they are displayed correctly on the page.This article will introduce in detail how to set your website logo and filing number in the Anqi CMS background, as well as how to correctly refer to them in the website template.### One, set up in the background First

2025-11-08

How to customize the layout and content of the document detail page in AnQi CMS?

In Anqi CMS, the custom display layout and content of the document detail page are crucial for realizing website personalization and meeting specific business needs.The ultimate form of website content, detail pages not only carry core information but also directly affect user experience and search engine optimization effects.The AnQi CMS offers a highly flexible template mechanism and rich data tags, allowing users to easily create unique document detail pages according to their own creativity.

2025-11-08

How to use AnQi CMS template tags to get the document list under a specific category?

AnQiCMS (AnQiCMS) provides a solid foundation for flexible display of website content with its powerful template features.In website operation, we often encounter the need to display a list of documents under specific categories, such as news updates, product introductions, blog articles, and so on.Mastering how to utilize template tags to achieve this function will greatly enhance the organization efficiency and user experience of the website content.### Core Tag: The Usefulness of `archiveList` In AnQi CMS, you need to get the document list under a specific category

2025-11-08

How to implement lazy loading display effect of images in AnQi CMS article content?

In website operation, the speed of image loading is crucial for user experience and Search Engine Optimization (SEO).Especially when an article contains a large number of images, loading all images at once will significantly increase page loading time, consume user traffic, and may cause users to leave prematurely.At this moment, the Lazy Load (Lazy Load) image technology can fully show its prowess.The core idea of lazy loading is to only start loading images when they are about to enter the user's visible area, rather than loading all of them at the initial page load.

2025-11-08

How to set and display the navigation menu (top/bottom) of the AnQi CMS website?

The website navigation is the key path for users to explore the website content, and it is also an important reference for search engines to understand the website structure.In AnQiCMS (AnQiCMS), you can flexibly set and manage the top and bottom navigation menus of the website to meet different design and functional requirements.This article will introduce how to configure the navigation menu in Anqi CMS backend, as well as how to display it in the website frontend template.## Part One: Back-end Configuration of Navigation Menu The navigation menu settings in AnQi CMS are concentrated in the "Back-end Settings" area of the back-end.

2025-11-08