How to display hot articles on the AnQiCMS homepage based on article views?

Calendar 👁️ 66

On AnQiCMS, the homepage is usually the important entry for visitors to understand the website content and quickly obtain information.Reasonably display popular articles, not only can attract users' attention, improve content exposure, but also effectively improve the user experience and PV (page views) of the website.AnQiCMS with its flexible template tags and built-in features makes this operation very simple and intuitive.

Understand how AnQiCMS counts page views

AnQiCMS has built-in article view count statistics, the system will automatically track the number of visits to each article and store this data.This means that you do not need to make any additional configuration or install any plugins, the views of each article will be silently recorded by the system from the day it is published.In the template, we can directly go throughitem.ViewsThis field is used to access the article's page view data, which provides the basis for us to filter and display popular content.

Positioning the display location of popular articles

Generally, the list of popular articles is placed on the homepage, sidebar, or prominent position of specific category pages on the website, so that users can see the most popular content as soon as they enter the site.For displaying popular articles on the homepage, we need to modify the corresponding template file on the homepage of the website.In AnQiCMS, the template file corresponding to the home page of the website is usually/template/你的模板目录/index/index.htmlIf you are using the default template of AnQiCMS, you can find it in its directoryindex/index.htmlfile.

UsearchiveListTag to get hot article data

AnQiCMS provides a powerfularchiveListTemplate tag, specifically used to obtain a list of articles. To implement displaying popular articles based on views, we need to cleverly utilizearchiveListSeveral key parameters of the tag:

  1. type="list": Because we simply list popular articles, usually do not need pagination, so willtypethe parameter tolist. This will return an article list without pagination logic.
  2. order="views desc": This is the core parameter for implementing popular articles. By usingorderthe parameter toviews desc, AnQiCMS will sort articles by the number of views from high to low.descDescending order, ensuring that the articles with the highest views are displayed at the top.
  3. limit="X": Bylimitparameter to limit the number of displayed items. For example, if you want to display 8 popular articles on the homepage, you can setlimitis set to"8".
  4. moduleId="Y": If your website has multiple content models (such as articles, products), and you only want to display specific content models (such as only displaying popular content under the 'article' model), you canmoduleIdThe parameter is specified. Usually, the ID of the 'Article' model is 1, and the specific ID can be viewed in the 'Content Management' -> 'Content Model' of the AnQiCMS backend.

Combine these parameters to obtain the template tags for popular article data:

{% archiveList hotArticles with type="list" order="views desc" limit="8" moduleId="1" %}
    {# 文章数据将在这里循环展示 #}
{% endarchiveList %}

Here, we will name the list of popular articles obtainedhotArticles.

Display popular articles in the template

After obtaining the data, we need to use a loop structure in the template to iterate and display each popular article. The AnQiCMS template engine supports something similar to Django'sforLoop. In the loop, each popular article will be asiteman object, we can use throughitem.Title/item.Link/item.ViewsAccess fields to view the title, link, and view count of the article. To make popular articles more attractive, we can also display the article's thumbnail (item.Thumb) and a brief description (item.Description).

This is an example of a code snippet displayed on the homepage template showing popular articles.

`twig

<h2 class="section-title">热门文章推荐</h2>
<ul class="article-list">
    {% archiveList hotArticles with type="list" order="views desc" limit="8" moduleId="1" %}
        {% for item in hotArticles %}
            <li class="article-item">
                <a href="{{ item.Link }}" title="{{ item.Title }}">
                    {% if item.Thumb %}
                        <div class="article-thumb-wrapper">
                            <img src="{{ item.Thumb }}" alt="{{ item.Title }}">
                        </div>
                    {% endif %}
                    <h3 class="article-title">{{ item.Title }}</h3>
                    <p class="article-views">浏览量:{{ item.Views }}</p>
                    {# 您也可以根据需要,加上文章的发布时间或简介 #}
                    {# <span class="article-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span> #}
                    {# <p class="article-description">{{ item.Description|truncatechars:8

Related articles

How to display article thumbnails in the Anqi CMS article list?

## How to Display Thumbnails Gracefully in AnQi CMS Article List Visual appeal of the article list page is crucial in website operation.A carefully selected or automatically generated thumbnail that can quickly catch the visitor's attention, convey the theme of the article, and thus improve click-through rate and optimize user experience.Our AnQi CMS provides flexible and powerful functions, helping us easily display article thumbnails in the article list.

2025-11-08

How to call and display custom parameter fields of articles in the Anqi CMS template?

In AnQi CMS, the custom parameter field of the article is an important manifestation of its core feature of 'flexible content model'.It allows us to define unique additional attributes for different types of content (such as articles, products), greatly enhancing the expressiveness of content and the customization capabilities of the website.Imagine if your website needs to display product details, in addition to the general information such as title, content, and images, you may also need specific parameters such as 'model number', 'color', 'storage capacity', and so on.These are the places where custom parameter fields take effect.

2025-11-08

How to customize the title display format of AnQi CMS article detail page?

The secret to flexibly customizing the CMS article detail page title display formatIt not only affects the identification of users in browser tabs and favorites, but is also one of the key elements of search engine optimization (SEO).A clear, attractive, and well-formatted title that can effectively improve the click-through rate of the article and the professional image of the website.

2025-11-08

How to display the latest published article list on the homepage of AnQiCMS?

In Anqi CMS, the homepage carries the important responsibility of attracting visitors and displaying the latest news.Generally, displaying the latest list of published articles in a prominent position on the homepage is an effective way to enhance user experience and guide content browsing.AnQi CMS with its flexible template system and powerful content management features makes this operation very direct and efficient.

2025-11-08

How to implement 'Previous' and 'Next' document navigation on the AnQiCMS article detail page?

In Anqi CMS, implementing the "Previous" and "Next" navigation functions on the article detail page is a key link in improving user experience, guiding users to delve deeper into the website's content, and also helps optimize the internal link structure of the website, which is greatly beneficial for SEO performance.AnQiCMS has a powerful template system and flexible tag features, making this operation intuitive and efficient.### How to implement 'Previous' and 'Next' document navigation in AnQiCMS AnQiCMS has designed a series of convenient template tags specifically for retrieving information about adjacent documents in the article detail page

2025-11-08

How to configure the lazy loading effect of images in the AnQiCMS article content?

In AnQiCMS, optimizing website loading speed is a key step to improving user experience and search engine rankings.When the article content contains a large number of images, these images will significantly increase the page loading time.Image lazy loading (Lazy Loading) is an efficient way to solve this problem, it can prevent images from loading until they enter the user's field of vision, thereby speeding up the initial rendering speed of the page.AnQiCMS as a content management system focusing on performance and SEO provides flexible support for lazy loading images in article content.You can configure the template simply

2025-11-08

How to correctly render Markdown formatted article content in AnQi CMS and display it?

Today, with the increasing efficiency in content creation, Markdown is favored by content creators for its concise syntax and focus on the content itself.AnQi CMS understands this trend and provides powerful features that allow you to easily convert Markdown-formatted article content into exquisite HTML pages and support richer display effects, such as mathematical formulas and flowcharts.

2025-11-08

How to display the associated Tag tag list on the AnQiCMS article detail page?

In website content operation, tags are important tools for connecting related content, enhancing user experience, and optimizing search engine rankings.AnQiCMS as an efficient content management system, naturally supports the association function between articles and tags.How can we clearly display these associated tags on each article's detail page to allow readers to quickly find more interesting content?This article will guide you in easily displaying the tag list on the article detail page of AnQiCMS.

2025-11-08