How to use the `archiveList` tag to sort and display the most popular article list by views?

Calendar 👁️ 76

How to navigate through in Anqi CMS?archiveListTag display hot article list?

In content operation, clearly displaying popular articles on the website to visitors can not only effectively improve user experience and guide users to discover more exciting content, but can also indirectly promote search engine optimization (SEO) through effective content distribution. Anqi CMS provides powerful and flexible template tag functions, among whicharchiveListTags are the core tools to achieve this goal. This article will guide you on how to utilizearchiveListTags, easily create a popular article list based on article views.

UnderstandingarchiveListThe core role of tags

archiveListThe tag is a universal tool in AnQi CMS used to retrieve and display document lists.It can filter content based on various conditions, such as by category, model, recommended attributes, and provide flexible sorting methods.For creating the 'Hot Articles' list, we mainly focus on its sorting function, especially how to sort based on the number of views.

UsearchiveListWhen you usually specify a variable name (such asarchives), so that you can access the article data in subsequent loops. The structure of the tag is roughly as follows:

{% archiveList 变量名称 with 参数1="值1" 参数2="值2" %}
    {% for item in 变量名称 %}
        {# 在这里展示文章内容 #}
    {% empty %}
        {# 没有内容时的提示 #}
    {% endfor %}
{% endarchiveList %}

Practice exercise: Step by step to implement the popular article list

To implement the popular article list, you need to edit the website template files. The template files of Anqi CMS are usually stored in/templatethe directory, and.htmlsuffix.

1. Basic list construction

First, let's create a basic article list framework. Suppose you want to display 5 popular articles in a sidebar or a block on the homepage.

<div class="hot-articles-list">
    <h3>热门文章</h3>
    <ul>
        {% archiveList archives with type="list" limit="5" %}
            {% for item in archives %}
                <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
            {% empty %}
                <li>暂无文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

This code will list 5 of the latest published articles with titles and links because the defaultorderparameters are usually in descending order by ID (i.e., the most recent published).

2. Add the page view sorting to create a 'popular' article

To make the list truly 'popular', we need to introduceorderThe parameter is set toviews desc. Here,viewsIt refers to the page views of the article, anddescDescending order, meaning the views are displayed from high to low.

<div class="hot-articles-list">
    <h3>热门文章</h3>
    <ul>
        {% archiveList archives with type="list" limit="5" order="views desc" %}
            {% for item in archives %}
                <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
            {% empty %}
                <li>暂无热门文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

Now, your list will display the top 5 most viewed articles from high to low based on the number of views.

3. Enrich the display content of popular article lists

Simply displaying the title may not be enough. You might also want to show views, publication dates, and other information to make the list more intuitive.archiveListin the loopitemThe object provides rich article fields for you to call, such asitem.Views(Views) anditem.CreatedTime(Creation time).

To better display the date, we can usestampToDatetags to format the timestamp.

<div class="hot-articles-list">
    <h3>热门文章</h3>
    <ul>
        {% archiveList archives with type="list" limit="5" order="views desc" %}
            {% for item in archives %}
                <li>
                    <a href="{{ item.Link }}">{{ item.Title }}</a>
                    <span>(浏览:{{ item.Views }} 次,发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }})</span>
                </li>
            {% empty %}
                <li>暂无热门文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

This code will display the article title, link, as well as their views and formatted publication date. You can add more information according to your needsitem.Thumb(thumbnail) oritem.Description(summary) and more information.

4. Optional: Filter popular articles by specified category or model

You can add extra settings if you want to display popular articles under a specific category, or only show the popular content of a specific content model (such as the "product" model)categoryIdormoduleIdParameter.

For example, display the popular articles of the article model with category ID 10 (assuming ID 1):

<div class="category-hot-articles-list">
    <h3>本分类热门文章</h3>
    <ul>
        {% archiveList archives with type="list" moduleId="1" categoryId="10" limit="5" order="views desc" %}
            {% for item in archives %}
                <li>
                    <a href="{{ item.Link }}">{{ item.Title }}</a>
                    <span>(浏览:{{ item.Views }} 次)</span>
                </li>
            {% empty %}
                <li>本分类暂无热门文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

By flexibly combining these parameters, you can create a hot content list to meet different scene requirements.

Some practical tips

  • Customize the style:The code only provides the HTML structure, you can customize the CSS styles fordiv/ul/liandatags according to the overall design of the website to make it more beautiful.
  • View count:The Anqi CMS is built-in with traffic statistics function, the page views of the articles (views) data is exactly sourced from here, no additional configuration is required to automatically accumulate.
  • Caching mechanism:The list of hot articles usually has a high number of visits, the static cache mechanism built-in to Anqi CMS can effectively alleviate server pressure and ensure page loading speed.If the list content is not updated in time, you can try to manually clear the background cache.
  • Application scenario:You can place the popular articles list on the homepage of the website, in the sidebar of the article detail page, at the top of the category page, or even as a recommended part of the email marketing content to enhance the exposure rate of the content and user interaction.

ByarchiveListTags, AnQi CMS makes the display of hot articles simple and efficient.You just need a few lines of code to dynamically present the most popular content based on page views, providing visitors with a better browsing experience.


Frequently Asked Questions (FAQ)

Q1: How are page views counted, and how is accuracy guaranteed?A1: Anqicms has built-in traffic statistics functionality, the page views of the article (ViewsIt is automatically recorded by the system.Each time a user visits the article detail page, the system will increase the page view count.The "Traffic Statistics and Spider Monitoring" module on the backend can help you view detailed traffic data.Although it is impossible to exclude all non-real user visits (such as web crawlers), for the general judgment of 'hot' on a website, this data is sufficiently accurate and valuable for reference.

Q2: What is the sorting rule if the article views are the same?A2: When multiple articles have the same view count, AnQi CMS will sort according to the default secondary sorting rules.In most cases, the system will fall back to sorting by the article ID in descending order, which means that in articles with the same number of views, the most recently published articles will be at the top.If you have specific needs for secondary sorting, you may need to further customize the label function or carry out secondary development.

Q3: Can I display popular articles from a specific time period? For example, 'Week's Most Popular' or 'Month's Most Popular'??A3:archiveListThe tag does not provide a direct parameter to filter 'hot' articles by time range.order="views desc"It will count the articles published on

Related articles

How to get and display the thumbnail or cover image of the article in the template?

The Anqi CMS has always been highly praised for its flexibility in content display, where images act as the core elements to attract users and convey information. How to efficiently and accurately obtain and display the thumbnail or cover image of the article in the template is a focus for many website operators.This article will thoroughly explain the Anqi CMS template mechanism and guide you step by step to master the skills of image calls.How does AnQi CMS intelligently handle images

2025-11-07

How to customize the template layout of article, product, and category pages?

In AnQi CMS, flexibly customizing the page template layout is a key step to enhancing website personalization and user experience.Whether it is an article, product detail page, or category list page, AnQi CMS provides powerful and intuitive tools to allow you to create unique and stylish pages without delving into programming.Let's explore how to bring your design concept to life in Anqi CMS.

2025-11-07

Where is the TDK (Title, Keywords, Description) information of the home page set and displayed?

The TDK (Title, Keywords, Description) information on the homepage is crucial for the performance of the website in search engines.It is not only the key for search engines to understand the core content of a website, but also an important basis for users to decide whether to click on a website in the search results page.AnQi CMS is an efficient content management system that provides an intuitive and convenient TDK management function, allowing us to easily optimize the visibility of the website homepage in search engines.

2025-11-07

How to display the multi-language content switch button on the website front end?

On AnQiCMS, it is crucial to display a multilingual content switch button on the website front-end to expand the global user base and enhance the user experience.AnQiCMS with its powerful multilingual support and flexible template mechanism makes implementing this feature intuitive and efficient. ### AnQiCMS multilingual mechanism overview AnQiCMS considered the needs of global content publishing from the outset.Its multilingual support is centered around the "multi-site management" feature.This means that you can create different sites to represent different language versions. For example

2025-11-07

How to display the second-level or multi-level category list in the navigation bar?

The website navigation is like the skeleton of your website, guiding visitors to browse different parts of the website and find the content they are interested in.A clear and intuitive navigation system is crucial for enhancing user experience and the professionalism of a website.AnQi CMS knows this, providing flexible and diverse solutions to build and manage website navigation, especially for complex navigation structures that need to display two-level or even multi-level classification lists.Today, let's delve deeper into how to set up and display these well-structured category lists in Anqi CMS, making your website navigation stronger and smarter.

2025-11-07

How to correctly render Markdown format in HTML and display mathematical formulas in the article content?

When using AnQiCMS to write articles, we often hope that the content is not limited to plain text or simple rich text, but can support richer formats, especially the convenience brought by Markdown syntax, as well as the indispensable mathematical formulas in scientific and technical content.This not only improves the quality of the content, but also provides readers with a better reading experience.AnQiCMS knows the importance of content diversity, and therefore provides Markdown support in the system.But let these Markdown contents, especially complex mathematical formulas

2025-11-07

How to display links to the previous and next articles at the bottom of the article detail page?

In Anqi CMS, adding navigation links for "Previous Article" and "Next Article" at the bottom of the article detail page can not only optimize the user's browsing path on the website, enhance the user experience, but also effectively increase page transitions, and is of great benefit to the internal link structure and SEO performance of the website.AnQiCMS is a powerful template engine with a rich set of tags, making it intuitive and efficient to implement this feature.### Core Function Analysis: Tags of the previous and next articles AnQiCMS template system provides a special function for retrieving tags of adjacent articles, respectively

2025-11-07

How to display the website's ICP record number and copyright information in AnQiCMS template?

In the operation of a website, the ICP filing number and copyright information are indispensable components for the legal operation and protection of the website's rights and interests.For websites operating in mainland China, the ICP record number is an explicit legal requirement. It not only guarantees the legality of the website but also enhances users' trust in the website.Copyright information specifies the ownership of the website content, helping to protect original works from infringement.

2025-11-07