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.