How to use the `archiveList` tag to sort and display the article list by views or publication time?

Calendar 👁️ 75

How efficiently to display and organize content in website operation often directly relates to user experience and the propagation effect of content.AnQiCMS provides a series of powerful and flexible template tags, allowing content managers to easily control the display of articles.Today, let's talk about how to usearchiveListTags, articles are displayed in order of their views or publication time.

UnderstandingarchiveListTag

archiveListThe tag is a core tool in AnQiCMS used to retrieve and display article lists.It can filter articles based on various conditions and sort them in the way you expect.Whether it is the latest news of building the homepage or the hot article recommendations on the category page,archiveListAll of them can provide strong support.

While usingarchiveListAt this time, you will usually see the following structure:

{% archiveList 变量名称 with 参数="值" %}
    {% for item in 变量名称 %}
        {# 这里是每篇文章的显示内容 #}
    {% endfor %}
{% endarchiveList %}

Among them,变量名称Is the list variable name you customize,参数="值"It is the key to controlling the behavior of the list. The focus of this article is onorderthis parameter.

Sorted by publish time: Display the latest articles

On many websites, visitors hope to see the latest content published, especially on news, blog, or technology sharing websites.AnQiCMS provides a concise way to achieve this.

Sort articles by publication time in reverse order (i.e., the most recent ones first), you canarchiveListUsed in tagsorder="id desc"In AnQiCMS design, the article ID is auto-incrementing, usually, the larger the ID means the later the article was published.

For example, if you want to display the latest 5 articles on the homepage:

{# 假设这是您的网站首页,显示最新的5篇文章 #}
<div class="latest-articles">
    <h3>最新发布</h3>
    <ul>
        {% archiveList latestArticles with type="list" limit="5" order="id desc" %}
            {% for article in latestArticles %}
                <li>
                    <a href="{{ article.Link }}">{{ article.Title }}</a>
                    <span class="publish-date">发布于: {{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
                </li>
            {% empty %}
                <li>暂无最新文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

If your list requires pagination, for example, on the article category page, displaying 10 articles per page, and sorted by publication time:

{# 假设这是文章分类页,每页显示10篇最新文章 #}
<div class="category-list">
    <h3>分类最新文章</h3>
    <ul>
        {% archiveList latestPaginated with type="page" limit="10" order="id desc" %}
            {% for article in latestPaginated %}
                <li>
                    <h4><a href="{{ article.Link }}">{{ article.Title }}</a></h4>
                    <p>{{ article.Description|truncatechars:100 }}</p>
                    <span class="publish-info">发布于: {{ stampToDate(article.CreatedTime, "2006-01-02 15:04") }}</span>
                </li>
            {% empty %}
                <li>该分类下暂无文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>

    {# 分页标签需要配合 type="page" 使用 #}
    <div class="pagination-controls">
        {% pagination pages with show="5" %}
            {# 这里是分页的渲染代码,例如首页、上一页、页码列表、下一页、尾页 #}
            {% if pages.FirstPage %}<a class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">首页</a>{% endif %}
            {% if pages.PrevPage %}<a class="page-item" href="{{pages.PrevPage.Link}}">上一页</a>{% endif %}
            {% for item in pages.Pages %}<a class="page-item {% if item.IsCurrent %}active{% endif %}" href="{{item.Link}}">{{item.Name}}</a>{% endfor %}
            {% if pages.NextPage %}<a class="page-item" href="{{pages.NextPage.Link}}">下一页</a>{% endif %}
            {% if pages.LastPage %}<a class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">尾页</a>{% endif %}
        {% endpagination %}
    </div>
</div>

here,type="page"TellarchiveListThis is a pagination list that needs to be coordinatedpaginationTags to generate page numbers and navigation.

Sorted by views: Display popular articles.

In addition to the latest content, popular articles are also important elements in attracting visitors. By displaying the articles with the highest views, you can help new visitors quickly understand the精华 content of the website.

Sort articles by the number of views in descending order (i.e., the highest number of views first), you can do it byarchiveListUsed in tagsorder="views desc".

For example, display 5 popular articles on the homepage:

{# 假设这是您的网站首页,显示最热门的5篇文章 #}
<div class="popular-articles">
    <h3>热门文章</h3>
    <ul>
        {% archiveList popularArticles with type="list" limit="5" order="views desc" %}
            {% for article in popularArticles %}
                <li>
                    <a href="{{ article.Link }}">{{ article.Title }}</a>
                    <span class="view-count">浏览量: {{ article.Views }}</span>
                </li>
            {% empty %}
                <li>暂无热门文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

If your popular article list also needs pagination:

"`twig {# This is the popular article category page, displaying 10 popular articles per page #}

<h3>分类热门文章</h3>
<ul>
    {% archiveList popularPaginated with type="page" limit="10" order="views desc" %}
        {% for article in popularPaginated %}
            <li>
                <h4><a href="{{ article.Link }}">{{ article.Title }}</a></h4>
                <p>{{ article.Description|truncatechars:100 }}</p>
                <span class="view-info">浏览量: {{ article.Views }}</span>
            </li>
        {% empty %}
            <li>该分类下暂无热门文章。</li>
        {% endfor %}
    {% endarchiveList %}
</ul>

{# 分页标签 #}
<div class="pagination-controls">
    {% pagination pages with show="5" %}
        {# 分页渲染代码与上述相同

Related articles

How to include external static resource files (CSS, JS, images) in a template?

When using AnQiCMS to build a website, introducing styles (CSS), interactive scripts (JS), and images as static resources is the foundation for the website's aesthetics and functionality.Understand how to correctly introduce these files in the template, so that your website not only looks professional but also has rich functions and maintains efficient and stable operation.AnQi CMS with its concise and efficient architecture and flexible template engine makes it very intuitive to manage and introduce these resources.The AnQiCMS template system, especially in handling static resources, is very thoughtful

2025-11-09

How to display the filing number in the footer and generate a link to the filing official website?

In website operation, especially for mainland Chinese users, correctly displaying the website's ICP filing number is an important aspect of compliance.The record number is usually located at the footer of the website and will link to the Ministry of Industry and Information Technology's government service platform (beian.miit.gov.cn), convenient for users to query and verify.An enterprise CMS provides users with a convenient way to configure and display this information. Next, we will introduce step by step how to display the record number in the footer of your Anqi CMS website and generate a link to the record official website.### First Step

2025-11-09

How to display a custom website logo and copyright information on the front end?

The website's logo and copyright information, like a business card, is an important manifestation of brand recognition and professionalism.They not only enhance the trust of users in the website, but also provide a direct display of the brand image and legal rights.In AnQiCMS, display these core brand elements, the process is simple and clear, allowing you to easily customize a unique image for your website.

2025-11-09

How to batch regenerate thumbnails to adapt to the new frontend display size requirements?

The website's front-end interface has been completely refreshed, you may find that the old thumbnail images do not fit well in the new layout, either the size is not right or the display effect is not good.Don't worry, AnQiCMS (AnQiCMS) provides you with a convenient and efficient solution to help you batch regenerate thumbnails and easily adapt to the new front-end display size requirements.Why do you need to regenerate thumbnails?The visual presentation of a website is crucial for user experience.

2025-11-09

How to implement showing or hiding part of the content based on user group permissions (such as VIP exclusive content)?

In website operation, providing differentiated content services based on user identity is a common strategy to enhance user experience and achieve content monetization.AnQiCMS (AnQiCMS) with its flexible user group management and VIP system, can help us easily implement content display or hide based on user permissions.This article will delve into how to use this feature of Anqi CMS to create exclusive VIP content for your website or display different information based on user level.

2025-11-09

How can you determine if a variable exists in a template and dynamically display content based on the result?

Build an energetic website on AnQiCMS, content management is not just about publishing information, but also about how to intelligently present these information.Imagine if your website could flexibly adjust the display style based on the actual data, for example, showing an image if there is one, and displaying alternative text if there isn't;If there is relevant content, recommend it; if not, kindly prompt The key to realizing this intelligent dynamic display lies in how to determine whether a variable exists in the template

2025-11-09

How to control the display of different styles for odd and even rows in a table or list loop?

In web design and content presentation, in order to enhance the user reading experience and make the information presentation clearer, we often need to apply different styles to the odd and even rows in tables or lists.This visual distinction not only breaks the monotony of the content, but also significantly improves the readability of the data.In AnQiCMS, with its flexible and powerful template engine, achieving this effect is quite direct and convenient.

2025-11-09

How can you format a timestamp to display the publication date in a friendly date and time format?

In website operation, the content publication date is not just a time mark, it is also an important basis for visitors to obtain information timeliness.A clear and readable date format that can significantly improve user experience and make your website content appear more professional and considerate.However, in a powerful content management system like AnQiCMS, the publication date is usually stored in the database in the form of a "timestamp", which is usually a string of numbers that is difficult to understand directly.For example, you might see a number like `1609470335`

2025-11-09