How to display the page views and comment count of the document?

Calendar 👁️ 95

In website content operation, accurately displaying the document's page views and the number of user comments is a key indicator of the popularity and user activity of the content.AnQiCMS provides flexible and intuitive template tags, helping us easily display these important data in all corners of the website without needing to delve into complex backend logic.

Display the number of views and comments on the document detail page

When you want to display the current number of views and comment counts on a single document detail page (such as an article, a product detail page) for AnQiCMS'sarchiveDetailTags are your preferred tool. This tag can retrieve detailed information about the document on the current page, including preset viewing and comment counts.

To display the document's view count, you can useViewsfield. For example, you can reference it in the template like this:

<span>阅读量:{% archiveDetail with name="Views" %}</span>

Or, if your template can directly access the document object, it can also be written more concisely:

<span>阅读量:{{archive.Views}}</span>

Similarly, to display the number of comments on the document, you can use:CommentCountfield. The referencing method is similar:

<span>评论:{% archiveDetail with name="CommentCount" %}条</span>

OR:

<span>评论:{{archive.CommentCount}}条</span>

Generally, this information is placed below the article title, next to the author's information, or at the bottom of the page, so that visitors can see it at a glance.

Display the number of views and comments on the document list page

If your website contains a list of articles, product lists, or other document aggregation pages, and you want to display the number of views and comments next to the thumbnail information of each document,archiveListThe tag is very applicable. This tag is used to loop out information of multiple documents, you can access the specific properties of each document within the loop.

While usingarchiveListWhen traversing the document list, the detailed data of each document will be assigned to the loop variable (usuallyitem)。At this time, you can accessitem.Viewsanditem.CommentCountto retrieve and display the corresponding data.

For example, in a template snippet of a document list, you can lay it out like this:

{% archiveList archives with type="list" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <div>{{item.Description}}</div>
            <div>
                <span>发布时间:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>阅读:{{item.Views}}</span>
                <span>评论:{{item.CommentCount}}条</span>
            </div>
        </a>
        {% if item.Thumb %}
            <a href="{{item.Link}}">
                <img alt="{{item.Title}}" src="{{item.Thumb}}">
            </a>
        {% endif %}
    </li>
    {% empty %}
    <li>
        该列表没有任何内容
    </li>
    {% endfor %}
{% endarchiveList %}

In this way, the title, summary, publication time, and corresponding number of views and comments of each document can be clearly displayed in the list.

Get the total number of comments in the current document's comment area

AnQiCMS in addition to providing document details,CommentCountOutside the field, if you have built a comment list on a specific page and want to display the total number of comments displayed on the current page (not the total comment count of the document, although these values may be the same in some cases), you can usecommentListLabel collaborationpaginationthe tag.

commentListThe tag itself is used to list comment content, but when it is used withpaginationthe tag together,paginationthe object will provide aTotalItemsThe property, which is the total number of items in the current comment list. This is particularly useful for comment sections that may have pagination.

Here is an example of how to get the total number of comments in the current document's comment section.

{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {# 评论列表内容... #}
{% endcommentList %}

{% pagination pages with show="5" %}
    <span>总评论数:{{pages.TotalItems}}条</span>
{% endpagination %}

Herearchive.IdRepresents the ID of the current document, ensuring that the comments of the document are retrieved. In this way, you can flexibly display different levels of comment quantity information according to your actual needs.

Useful Tips

In practice, you can consider the design style of the website and user experience to flexibly adjust the display position and style of this information.For example, use CSS to iconize and highlight reading volume and comment count, making it more attractive.The AnQiCMS template system aims to provide high customizability, allowing you to easily create website content display effects that match your brand image.

Frequently Asked Questions (FAQ)

  1. Why is it that when I set the page view display, the frontend always shows 0 or does not update?

    • Answer:First, please confirm that the template tag you are using is correct (for example{{archive.Views}}or{{item.Views}})。The page views are usually counted and updated in real-time when users visit the document detail page, and you can try visiting the document detail page several times to trigger the count.If the problem persists, it may be necessary to check if the website's cache is updated in time, or contact the administrator to check if the backend statistics function is operating normally.
  2. Ask: Is the number of comments on the document updated in real time? Will new comments be displayed immediately?

    • Answer:The number of comments on the document is dynamically updated. When new comments are submitted and approved by the backend (if comment approval is enabled), the number of comments on the document will increase accordingly.The display on the front-end page will vary according to your page caching strategy, clear the cache or wait for the cache to refresh to see the latest number of comments.
  3. Ask: Can I make the number of views or comments visible only to a specific user group?

    • Answer:AnQiCMS itself does not provide a direct configuration option for "View count/Comment count visible only to specific user groups". However, you can combine it withifThe logic judgment and user group management function of AnQiCMS can be implemented.For example, determine if the current user belongs to a certain user group, if so, display the number of views and comments, otherwise hide.This requires a certain ability to write template logic. AnQiCMS supportsarchive.ReadLevelField, can be used to control the reading level of the document, combined with user identity, theoretically it can also realize more complex permission control.

Related articles

How to customize the display of thumbnail and cover images for articles or products?

In website content operation, the visual appeal of images is crucial.Whether it is to show the essence of an article or highlight the highlights of a product, a suitable thumbnail and cover image can greatly enhance the user experience and have a positive impact on the spread of content.AnQiCMS (AnQiCMS) offers rich and flexible features, allowing us to easily customize the display of images for articles or products according to specific needs.This article will introduce how to manage and display thumbnails and cover images in AnQi CMS from two aspects: background configuration and template calling.--- ### One

2025-11-07

How to display the list of recommended content related to the current document in AnQi CMS?

When operating a website, we often hope that users can smoothly find more interesting content after reading a wonderful article.This not only extends the user's stay time and reduces the bounce rate, but is also an effective way to enhance the overall value of the website's content and SEO performance.AnQi CMS knows this, and therefore it provides a variety of flexible ways to display the recommended content list related to the current document, helping us better guide users. To implement recommendations for related content, we first need to understand how Anqicms defines 'related'.In system design, "related" can be reflected at several levels

2025-11-07

How to get and display the previous/next content of the current document?

In content-based websites, providing visitors with a convenient navigation experience is crucial, among which the 'Previous' and 'Next' functions are standard features of the article detail page.They can not only guide users to continue browsing more content, effectively increase the website's PV (Page View), but also help search engines better understand the structure of the website's content to optimize SEO performance.AnQiCMS fully considered this requirement, providing us with very simple and intuitive template tags to easily implement this feature.### Learn about AnQiCMS template mechanism At

2025-11-07

How to display the detailed content of articles or products and support lazy loading of images?

A Guide to Displaying Content Details and Lazy Loading Images in AnQi CMS in Today's Digital World, the way websites present content directly affects user experience and search engine rankings.Whether it is a detailed article introduction or a beautiful product display, how to present the content efficiently and aesthetically to the visitors and ensure the website loading speed is a challenge that every operator needs to face.AnQiCMS (AnQiCMS) is a powerful content management system that provides us with flexible tools to meet these challenges.This article will delve into how to fully utilize the functions of Anqi CMS

2025-11-07

How to specify and display different templates for specific documents or categories?

AnQi CMS provides a flexible and powerful template management mechanism that allows users to specify and display unique templates for documents, categories, and even single pages based on different content types or specific needs.This feature greatly enhances the personalized display capabilities and operational efficiency of the website content.Understanding the significance of template customization In website operations, the diversity of content often requires different presentation methods.An in-depth technical article may require a concise and clear layout so that readers can focus on the content itself;A promotional activity page may require prominent visual elements and call-to-action buttons

2025-11-07

How to display extra field data under a custom content model in Anqi CMS?

In AnQi CMS, the flexibility of the content model is one of the highlights of the project, allowing us to create and manage various content structures according to the actual business needs.Whether it is an article, product, event, or any other information that requires a specific field to describe, it can be easily realized through a custom content model.After adding exclusive additional fields to these models, the next step naturally is how to accurately and beautifully display this valuable data on the website front-end.This is not a complex task, Anqi CMS provides intuitive and convenient template tags to complete it

2025-11-07

How to display single page content on the front end of a website (such as About Us, Contact Us)?

In website operation, single-page content like "About Us" and "Contact Us" is indispensable, as it carries important functions such as displaying corporate image, providing contact information, or stating service terms.For friends using AnQiCMS, it is actually a very direct and flexible thing to beautifully display these single-page contents on the website front end. ### Single Page Content Management Overview Firstly, we need to create and manage these single pages in the AnQiCMS backend system.In the left navigation bar of the background, you can find the "Page Resources" menu

2025-11-07

How to display and manage the display of images and video multimedia resources?

In website operation, high-quality multimedia content is the key to attracting visitors and improving user experience.AnQiCMS (AnQiCMS) is well-versed in this, providing comprehensive features to help users easily manage and flexibly display images and videos on their websites.From unified resource library to intelligent optimization settings, AnQiCMS makes multimedia management efficient and convenient. ### One, Core Multimedia Management Center: Image Resource Management Anqi CMS gathers all uploaded images and video resources into a centralized "Image Resource Management" module.This is not only the place where you store your materials

2025-11-08