How to dynamically retrieve and display an article list through template tags in Anqi CMS?

Calendar 78

Dynamic display of website content is one of the core elements of modern website operations, it not only improves user experience and allows visitors to easily find the information they are interested in, but also effectively assists in search engine optimization (SEO), making the website more favored by search engines.In AnQi CMS, through the powerful template tag feature, we can flexibly retrieve and display various types of article lists.

The AnQi CMS template system borrows the syntax of the Django template engine, with a natural and smooth style. It will be very quick for you to get started if you are familiar with front-end development. We mainly use two symbols to operate in the template file: double curly braces{{ 变量 }}Used to output variable content, while the single curly bracket plus percent sign{% 标签 %}is used to perform logical judgments, loops, or call specific function tags.

Core Tool:archiveListTag

To dynamically retrieve and display the article list, we first need to understand the "universal" tag in Anqi CMSarchiveList. This tag is the foundation for building article lists, providing rich parameters to help us accurately filter, sort, and display articles.

Basic article list acquisition

If you just want to display a few of the latest articles on a single page, without pagination, thenarchiveListthe tag will be very simple and practical. We usually give this tag a variable name, such asarticlesThen proceedforLoop through this variable to display the information of each article.

For example, to display the titles and summaries of the 5 latest articles on the homepage:

<div class="latest-articles">
    {% archiveList articles with type="list" limit="5" order="id desc" %}
        {% for item in articles %}
            <article>
                <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
                <p>{{ item.Description }}</p>
                <footer>
                    <span>发布日期:{{ stampToDate(item.CreatedTime, "2006年01月02日") }}</span>
                    <span>浏览量:{{ item.Views }}</span>
                </footer>
            </article>
        {% empty %}
            <p>暂无文章内容。</p>
        {% endfor %}
    {% endarchiveList %}
</div>

In this code block:

  • archiveList articlesDefined a namedarticlesThe variable used to store the list of retrieved articles.
  • type="list"Indicates that we are getting a fixed number of lists, not prepared for pagination.
  • limit="5"Limited to displaying only the latest 5 articles.
  • order="id desc"Tell the system to sort articles by article ID in descending order, which usually means the most recent ones are at the top. You can also useorder="views desc"sort by views, ororder="sort desc"sort by backend custom sorting.
  • for item in articlesLoop througharticlesEach article in the variable, assigns the data of the current article toitem.
  • item.Link/item.Title/item.Description/item.ViewsAll are attributes of each article, which can be accessed through.the syntax.
  • stampToDate(item.CreatedTime, "2006年01月02日")It is a very useful time formatting function. The timestamp in AnQi CMS is usually 10 digits long, and you need to usestampToDatePass the Go language time format (for example “2006-01-02”) so that it can be converted to the date format we are familiar with.
  • {% empty %}the block will bearticlesWhen the list is empty, it is displayed to avoid the page from being blank.

If you need to display the thumbnail of the article, you can make use ofitem.Thumboritem.Logoproperties. To ensure that the image is displayed only when it exists, you can combineifthe tag to use:

{% if item.Thumb %}
    <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-thumb" />
{% endif %}

CombinemoduleIdRetrieve specific content model article

AnQi CMS supports a flexible content model, which means you may not only have the 'Article' model, but also other models such as 'Product', 'Case', and others. If you want to get a list of articles under a specific model, you need to usemoduleIdParameters. Usually, the "article model" ofmoduleIdWith1is the "product model".2. You can view the specific ID in the content model management on the back end.

For example, get the latest 5 product lists:

{% archiveList products with type="list" moduleId="2" limit="5" order="id desc" %}
    {% for product in products %}
        <div class="product-item">
            <a href="{{ product.Link }}">
                {% if product.Logo %}
                    <img src="{{ product.Logo }}" alt="{{ product.Title }}" />
                {% endif %}
                <h3>{{ product.Title }}</h3>
            </a>
            <p>{{ product.Description }}</p>
        </div>
    {% endfor %}
{% endarchiveList %}

Implement pagination: Make the article list easier to browse

Pagination is an essential function when there are many articles. To implement pagination lists in Anqi CMS,archiveListwith the tag andpaginationtag usage

first, archiveListit is necessary to transfertypeis set to"page"Specify the number of items per pagelimitThen, inarchiveListlabel'sendarchiveListAfter that, we usepaginationtags to generate pagination navigation.

Here is an example of an article list with pagination

`twig

{% archiveList articles with type="page" limit="10" %}
    {% for article in articles %}
        <article class="article-item">
            <h2><a href="{{ article.Link }}">{{ article.Title }}</a></h2>
            {% if article.Thumb %}
                <img src="{{ article.Thumb }}" alt="{{ article.Title }}" />
            {% endif %}
            <p class="article-description">{{ article.Description }}</p>
            <div class="article-meta">
                <span>分类: {% categoryDetail with name="Title" id=article.CategoryId %}</span>
                <span>浏览量: {{ article.Views }}</span>
                <span>发布时间: {{ stampToDate(article.CreatedTime, "2006年01月02日") }}</span>
            </div>
        </article>
    {% empty %}
        <p>这里暂时没有文章。</p>
    {% endfor %}

    <div class="pagination-nav">
        {% pagination pages with show="5" %}
            <a href="{{ pages.FirstPage.Link }}" class="page-link">首页</a>
            {% if pages.PrevPage %}<a href="{{ pages.

Related articles

How to configure Anqi CMS to support responsive design or independent mobile content display?

In the era of co-existing multiple devices, websites that can adapt well to various screen sizes, whether PC, tablet, or mobile phone, have become a basic requirement.AnQiCMS (AnQiCMS) understands this and provides a variety of flexible configuration options to help you easily implement responsive design or independent mobile content display, ensuring that your content brings users a high-quality browsing experience on any device.The Anqi CMS provides three main website modes to support multi-terminal display: adaptive, code adaptation, and PC+mobile independent sites

2025-11-08

How to implement independent templates for different pages (such as articles, products, single pages) in Anqi CMS?

In website operation, we often need to adopt completely different layouts and design styles for different types of content, such as a deep article, a product display page, or an 'About Us' single page.This differentiated display not only enhances user experience, but also helps content better convey information and achieve marketing goals.AnQiCMS (AnQi CMS) provides a very flexible and powerful solution in this regard, allowing us to easily implement independent templates for different pages.

2025-11-08

How to customize the display layout of content on the frontend page in Anqi CMS?

AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides us with great freedom with its powerful template functions and content model, allowing us to finely control the layout of content on the front-end page according to the actual needs of the website.To achieve this goal, we need to deeply understand the template engine, content model, and built-in tags of Anqicms.

2025-11-08

How to efficiently organize and reference common page header, footer, and other code snippets in the front-end page template?

Manage front-end page code in AnQi CMS, especially the header, footer, and other code snippets that need to be repeated on multiple pages, which is a key to improving development efficiency and website maintainability.AnQi CMS provides a powerful and flexible template engine, allowing us to organize and reference these common codes in an elegant way. ### The Importance of Template Reusability Imagine if your website has dozens, even hundreds of pages, each of which independently contains the complete header, navigation, and footer code. When the website's logo needs to be replaced, or the footer copyright information needs to be updated

2025-11-08

How to filter and display specific content lists based on categories, modules, or recommended attributes?

When using AnQi CMS to manage website content, we often need to display specific content (such as articles, products) in the form of a list in different areas of the website.This may mean that we need to display the latest headline articles on the homepage, only show products from a specific series on the product category page, or recommend some popular content in the sidebar.AnQi CMS provides flexible tags, allowing us to accurately filter and display the content list we need based on various conditions such as categories, content models, or recommendation attributes.

2025-11-08

How to implement the complete information display of the content detail page in AnQi CMS (including custom fields)?

In website operation, the content detail page is the core entry for visitors to understand products or services, and the completeness of information display and user experience is crucial.AnQiCMS (AnQiCMS) takes full consideration of the flexibility and customization of content display in its design, even for various custom fields you define, they can also be presented elegantly on the content detail page.Next, we will explore how to fully display all the information of the content detail page in Anqi CMS, from the establishment of the content model to the call of the template, including those unique custom fields.### Build Content Skeleton

2025-11-08

How to optimize image display in content lists and detail pages (thumbnails, multiple images, lazy loading)?

In the digital age where content is king, images on websites are not only visual decorations but also key elements in attracting users, conveying information, and enhancing brand image.However, unoptimized images may also become the culprit that slows down website loading speed, affects user experience, and even damages SEO performance.Fortunately, AnQiCMS (AnQiCMS) provides us with a comprehensive and powerful image optimization tool, allowing the website to maintain visual appeal while achieving high-performance loading.

2025-11-08

How to dynamically display the website navigation menu in Anqi CMS, including secondary or multi-level dropdown menus?

In website operation, a clear and intuitive navigation menu is the foundation of user experience.A well-designed navigation system not only helps visitors quickly find the information they need but also effectively guides them through the browsing path within the website, which has a significant impact on the website's usability and SEO performance.Anqi CMS understands its importance and provides a flexible and powerful navigation management function, allowing you to easily implement dynamic, multi-level navigation menus without writing complex code.

2025-11-08