How to display the view count of articles in the article list or detail page?

Calendar 👁️ 69

In website operation, the number of page views of articles is a very intuitive and important indicator, which not only reflects the popularity of the content, but also provides data support for subsequent content strategy optimization.It is a relatively simple operation to display the number of views on articles in the article list or detail page of a website built with AnQiCMS, and we can easily achieve this by taking advantage of the powerful template tag functions provided by AnQiCMS.

Understanding the 'page views' feature of AnQiCMS

AnQiCMS comes with powerful traffic statistics functionality, the system automatically records the number of visits for each article, product, or page.This feature is part of AnQiCMS as a key highlight of "traffic statistics and crawler monitoring", aiming to help users fully understand the performance of the website.This means that we can display this valuable data on the front page without any additional configuration, allowing visitors to also see the popularity of the content.

Display the number of page views on the article detail page

When you visit a specific article, you will enter its detail page. On this page, AnQiCMS providesarchiveDetailTag to get the details of the current article. To display the number of views of the current article, you just need to be in the template file of the details page (for examplearchive/detail.htmlor the one you customize for a specific content modelyour-model/detail.htmlFind the appropriate position in the middle and embed the corresponding tag.

The specific code snippet is very concise:

{% archiveDetail with name="Views" %}

Generally, we would like to add some descriptive text to the number of views, such as

阅读量:{% archiveDetail with name="Views" %}

You can also choose to assign the page views to a variable and then perform subsequent operations or display. For example, if you want to add a unit 'times' after the page views, you can do it like this:

{% archiveDetail archiveViews with name="Views" %}
浏览次数:{{ archiveViews }} 次

Choose a suitable position on the page, such as below the article title, next to the publication time, or near the author information, add this code in, save the template file and refresh the page, and you will see the current page views of the article.

Display page views on the article list page

On the article list page, such as the article recommendation area on the homepage, the category list page, and even the search results page, displaying the reading volume of each article can also improve the user experience.Visitors can easily see which content is more popular, thus helping them make click choices.

AnQiCMS providesarchiveListtags to display the article list in a loop. InarchiveListthe loop body of the tag, the data of each article will be assigned to aitemVariable. You can accessitem.Viewsto get the reading volume of the article.

You can inarchive/list.htmlor other related template files (such asindex/index.htmlto find the article module section in{% archiveList ... %}the loop area, which is usually{% for item in archives %}Or a similar structure. Then embed the code snippet in it:

{% archiveList archives with type="list" limit="10" %}
    {% for item in archives %}
    <article>
        <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
        <p>{{ item.Description }}</p>
        <footer>
            <span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
            <span class="views-count">浏览量:{{ item.Views }}</span> {# 在这里显示浏览量 #}
        </footer>
    </article>
    {% empty %}
    <p>暂时没有文章。</p>
    {% endfor %}
{% endarchiveList %}

In the above example,item.ViewsIt will output the view count of each article. You can place it in the most suitable position according to your template structure.<span>浏览量:{{ item.Views }}</span>Place it in the most suitable position.

Tips for actual operation

  1. Style beautification:The display of pure numbers may not be aesthetically pleasing, you can use CSS to style it, such as adding icons to the number of page views, adjusting font size or color, so that it is consistent with the overall design style of the website.
  2. Default value handling:Sometimes, newly published articles may not have generated page views yet, or there may be a delay in data statistics.To avoid displaying blank spaces, you can consider using AnQiCMS's filter to set the default value.For example, it can be useddefaultFilter whenitem.ViewsDisplay "0" when empty:
    
    浏览量:{{ item.Views|default:"0" }}
    
  3. Improve user experience:The display of page views is not just for display, it can also guide users to discover popular content, stimulate user interaction (such as comments), and even in some cases act as an indirect indicator of search engine optimization (SEO) because high page views usually mean higher content quality, which helps improve the overall performance of the website.

By performing these simple operations, you can easily implement the display of article views on websites built with AnQiCMS, providing visitors with more information and bringing more data insights for website operations.


Frequently Asked Questions (FAQ)

  1. Why is my article view count showing 0 or not displayed?This usually has several reasons. First, the newly published articles may indeed not have generated any traffic yet;Secondly, it may be due to caching reasons, the caching mechanism of AnQiCMS may cause the front-end page to fail to update the page view data in time. You can try to update the cache in the background or wait for a while before viewing.Finally, if none of the above situations apply, please check if your template code is correct and if the tag names are spelled correctly.

  2. Is the view count data updated in real time? Can I manually modify or reset the view count?AnQiCMS's page view data will increase in real-time with each page visit.This means that every visit by a visitor is counted. As for manually modifying or resetting the number of page views, the AnQiCMS backend usually does not provide a direct manual modification feature for the page views of a single article, which is to ensure the authenticity and accuracy of the data.If there is a special requirement, it may be necessary to operate at the database level, but this is not recommended for ordinary users to try in order to avoid data confusion.

  3. Can articles be sorted by views?Yes, it is AnQiCMS'sarchiveListTags support various sorting methods, including sorting by views. You canarchiveListthe tag withorder="views desc"Parameters, to implement the display of articles sorted by views from high to low. For example:

    {% archiveList archives with type="list" order="views desc" limit="10" %}
    

    This allows you to easily display the most popular articles on the website.

Related articles

How to display a custom Banner image group on the category page or single page?

It is crucial that visual content is attractive in website operation.Especially for category pages and standalone single pages, displaying a set of carefully designed banner images can effectively attract visitors' attention, strengthen the brand image, and convey specific information.AnQiCMS provides a straightforward and flexible mechanism that allows you to easily configure and display custom Banner image groups on these key pages.

2025-11-08

How to display recommended attributes (such as headlines, recommendations, sliders) in article lists or detail pages?

In AnQi CMS, in order to make your website content more attractive and able to flexibly display articles of different importance levels or display forms, the system provides a "recommended attribute" feature.By cleverly utilizing these properties, you can easily add "headlinesThis guide will take you in-depth to understand how to set and use these recommended properties in AnQiCMS, making your website content management more convenient.

2025-11-08

How to set up the website to display specific notification information on the front end when it is in "closed site" status?

The website will always encounter times when it needs to be maintained, upgraded, or temporarily adjusted.At this moment, it is crucial for users to see a friendly and clear prompt instead of a cold error page, which is vital for the image and user experience of the website.Fortunately, AnQiCMS provides a very convenient and flexible "shutdown" function, allowing you to easily manage the maintenance status of the website and display customized notification information to front-end visitors.Next, let's take a look at how to set the "shutdown" status of the website in the AnQiCMS backend

2025-11-08

How to batch regenerate all content thumbnails to fit the new frontend display size?

When the visual style of a website needs a complete overhaul, or to adapt to the ever-changing size of device displays, we often need to adjust the size of image thumbnails.AnQiCMS (AnQiCMS) fully understands this and provides a convenient and efficient solution for such needs.How to batch regenerate thumbnails for all content in response to adjustments in front-end display dimensions to ensure the aesthetic beauty and loading efficiency of the website, which is a concern for many operators.Why do you need to regenerate the thumbnail? Thumbnails play a crucial role in website operations

2025-11-08

How to remove empty lines generated by conditional judgment or loop tags in the template to optimize the display cleanliness of the page source code?

In website operation, we all hope that the website is not only powerful in function, rich in content, but also the source code behind it should be neat and orderly.However, when developing with a flexible template system like AnQiCMS, you may sometimes find that the generated HTML source code contains many blank lines, which are mainly caused by conditional judgment or loop tags in the template.Although these blank lines usually do not have a substantial impact on the functionality of the website, they do indeed reduce the readability of the source code, and bring inconvenience to subsequent maintenance and debugging.

2025-11-08

How to render Markdown content into HTML in AnQiCMS?

In a content management system, Markdown is a lightweight markup language that allows content creators to write in plain text and format it with simple symbols, which can then be easily converted into structured HTML.For AnQiCMS users, using Markdown to write content not only improves efficiency but also ensures consistency and maintainability of content formatting.

2025-11-08

What is the specific usage of the `render` filter in Markdown content rendering?

In Anqi CMS, we often encounter the need to convert text into colorful web elements.Especially when content is written in Markdown format, how to ensure that it can be presented correctly and beautifully to the user is a problem that requires a deep understanding.Today, let's talk about how the `render` filter works in the Anqi CMS Markdown content rendering.

2025-11-08

How to manually control the Markdown to HTML rendering of the `Content` field of the document?

In a content management system, Markdown, as a lightweight markup language, is widely popular for its simplicity and efficiency.AnQiCMS (AnQiCMS) fully understands the importance of content flexibility to users and therefore provides a flexible mechanism for handling the Markdown rendering of document content.When you need to manually control the Markdown to HTML rendering of the `Content` field in the document, the system provides an intuitive and powerful method.### Understanding the AnQi CMS Markdown processing mechanism First

2025-11-08