How to retrieve and display the publish time, update time, view count, and comment count of an article?

Calendar 👁️ 69

Mastering AnQi CMS: A Comprehensive Guide to Article Publishing and Interactive Data Display

In website operations, clearly displaying the publication and update time of articles, popularity (page views), and reader feedback (number of comments) can not only effectively improve user experience but also enhance the authority and timeliness of the content.AnQiCMS (AnQiCMS) with its flexible template tag system makes it simple and efficient to obtain and display this key information.This article will explain in detail how to implement these features in Anqi CMS.

1. Data acquisition on the article detail page

When you browse a specific article, you hope to see its publication time, the latest update time, how many times it has been read, and how many comments there are. Anqi CMS provides this for you.archiveDetailLabel, this is a tool to get detailed information of a single article.

1. Get the article publish time (CreatedTime)

The article publish time records the time when the content first went online. In AnQi CMS,archiveDetailThe tag can easily retrieve this information. Since it returns a timestamp, we need to cooperatestampToDatetag to format it into a readable date and time.

For example, if you want to display the publication date of an article, you can use the following code:

发布时间:{{ stampToDate(archive.CreatedTime, "2006-01-02") }}

Here"2006-01-02"It is the time format defined by the Golang standard library, representing year, month, and day. If you need to display more detailed time, such as including hours, minutes, and seconds, you can adjust it as follows:

发布时间:{{ stampToDate(archive.CreatedTime, "2006-01-02 15:04:05") }}

2. Get the article update time (UpdatedTime)

The update time of the article is very important for readers, as it indicates whether the content is up-to-date. The method of obtaining the update time is similar to the publication time, and it also requires the use ofarchiveDetailTags andstampToDateto format.

更新时间:{{ stampToDate(archive.UpdatedTime, "2006-01-02 15:04:05") }}

It is recommended to display both the publication time and the update time in the template, or only display the update time when the content of the article is updated, to avoid redundancy.

3. Obtain the article view count (Views)

The number of page views of an article is a direct indicator of its popularity. Anqi CMS automatically counts the page views of each article and provides you witharchiveDetailtags.

浏览量:{% archiveDetail with name="Views" %}

Or if you have already passed through the templatearchiveYou can directly use a more concise way to get the current article object,

浏览量:{{ archive.Views }}

4. Get the number of comments on the article (CommentCount)

Readers' comments are a reflection of the interaction of the article. Anqi CMS'sarchiveDetailTags also include the function of getting the total number of comments, which is convenient for you to show the discussion热度 of the article.

评论数量:{% archiveDetail with name="CommentCount" %}

Similarly, in the already obtainedarchiveIn the case of variables, it can also be used:

评论数量:{{ archive.CommentCount }}

Second, display this information in the article list

In addition to displaying this information on the article detail page, it is also important to show it in the article list (such as the homepage, category page, tag page). For the article list, we usually usearchiveListLabel for loop output. InarchiveListThe loop body, each article item will be provided to you as aitemvariable. You can use it in the same way asarchiveDetailto obtain and display the data.

Here is a comprehensive example of displaying the publication time, viewing volume, and comment number in an article list:

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
    <article>
        <h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
        <div class="article-meta">
            <span>发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
            {% if item.UpdatedTime != item.CreatedTime %} {# 仅在更新时间与发布时间不同时显示 #}
            <span>更新于:{{ stampToDate(item.UpdatedTime, "2006-01-02 15:04") }}</span>
            {% endif %}
            <span>浏览:{{ item.Views }} 次</span>
            <span>评论:{{ item.CommentCount }} 条</span>
        </div>
        <p>{{ item.Description }}</p>
        <a href="{{ item.Link }}" class="read-more">阅读全文</a>
    </article>
    {% empty %}
    <p>暂时没有文章可供显示。</p>
    {% endfor %}
{% endarchiveList %}

In this example, we go throughitem.CreatedTime/item.UpdatedTime/item.Viewsanditem.CommentCountAccessed the corresponding data of the current article in the loop. Particularly, through{% if item.UpdatedTime != item.CreatedTime %}The condition judgment can ensure that only the actual content of the article is updated, and the update time will be displayed, avoiding redundant information.

Three: Tips for improving user experience

  • Aesthetically beautify the style:Use CSS to format and beautify this information, such as using icons (eye icons for views, speech bubble icons for comments) or different colored fonts to make it more attractive.
  • Conditional display:For the number of comments, if it is 0, you can choose not to display the number of comments or display 'No comments', to improve the user experience.Similarly, the update time can also be conditionally judged.
  • Flexible location:This information does not necessarily have to be placed below the article title. You can place it at the bottom of the article, in the sidebar, or any suitable position according to your design needs.

By following this method, you can easily present the key dynamic data of the article clearly to your readers on the website built with Anqi CMS, making your content more vibrant.The powerful template tag system of Anqi CMS allows you to have great freedom and convenience in content operation and front-end display.


Frequently Asked Questions (FAQ)

Q1: Why does the article's publish time or update time display a series of long numbers instead of specific date and time?A1: This is usually because you have directly outputtedCreatedTimeorUpdatedTimeVariables, they are stored internally in the AnQi CMS as Unix timestamps (a series of numbers). To convert them to a human-readable date and time format, you need to usestampToDateTemplate tags for formatting, for example{{ stampToDate(item.CreatedTime, "2006-01-02 15:04:05") }}.

Q2: Is the data of the article's page views updated in real time, where is it counted?A2: Anqi CMS is built with traffic statistics functionality, the article view data is usually updated in real time or almost real time.This data will be displayed in the "Data Statistics" module on the backend, where you can view more detailed traffic analysis and spider monitoring reports to understand the performance of your website.In scenarios with particularly high concurrency, CMS may adopt certain caching strategies to alleviate database pressure, but the data displayed on the front end will still maintain a high timeliness.

Q3: The number of comments on my article shows 0, but there are comments in the background. What's the matter?A3: Please check the background comment management module to confirm whether these comments have been approved.The default setting of Anqi CMS only counts and displays the number of comments that have been approved.Comments that are pending review, awaiting processing, or marked as spam will not be counted in the total number of comments displayed on the front end.Ensure that the comment status is 'approved' to display normally.

Related articles

How to display the name, link, and hierarchy of the article category on the article detail page?

AnQi CMS is a flexible and efficient content management system that provides great freedom in content display.For a website, the article detail page not only needs to display the content of the article itself, but also the name, link, and even the hierarchical relationship of the category it belongs to, which are all important components for improving user experience, optimizing website structure, and promoting SEO.Clear categorization information can help users quickly understand the positioning of the article, facilitate their further browsing of related content, and also enable search engines to better crawl and understand the structure of the website.Next, we will discuss how to use the Anqi CMS article detail page

2025-11-08

How to correctly display images in the article content of AnQiCMS templates and support lazy loading of images?

In content operation, exquisite images can significantly enhance the attractiveness and reading experience of articles.However, image files are often large, and if not handled properly, they may slow down page loading speed, affect user experience, and even search engine rankings.AnQiCMS fully understands this, providing a flexible way to correctly display images in article content within templates, and supports lazy loading of images to balance aesthetics and performance.### Core: Display images in article content In the AnQiCMS template, to obtain the main content of the article, we mainly rely on `{%

2025-11-08

How to obtain and display the title and detailed content on the article detail page?

Manage website content in Anqi CMS, the article detail page is an important window for displaying core information to visitors.Whether it is corporate news, product introduction, or technical articles, clearly presenting the title and detailed content is the key to improving user experience and information communication efficiency.The Anqi CMS provides intuitive and powerful template tags, making content presentation easy and flexible. ### Understanding Anqi CMS Template Structure Anqi CMS template files are usually stored in the `/template` directory and follow a set of simple naming conventions.for the detail page of an article or product document

2025-11-08

How to declare a temporary variable in AnQiCMS template and use it to display content, improving template flexibility?

In the template creation of Anqi CMS, we often need to display various dynamic content.It is crucial to be proficient in using temporary variables to make templates more flexible and code more concise.The Anqi CMS template engine provides powerful functionality for declaring temporary variables, which helps us better organize and process data, thereby improving the efficiency and maintainability of content display.### Understanding the Value of Temporary Variables Imagine that you need to display processed data at multiple locations on the page, or that a piece of data is used repeatedly in conditional judgments, or that data obtained from a tag needs to be further processed before it can be presented

2025-11-08

How to display the cover image, thumbnail, or group image of an article on the article detail page?

In Anqi CMS, adding images to the article detail page is an important link to improve the attractiveness of the content and the reading experience, whether it is the cover main image, thumbnail, or multiple group images.Anqi CMS provides a flexible and intuitive way to manage and display these image resources, allowing you to easily achieve diverse visual presentations. ### The Flexible Use of Article Cover Image and Thumbnail In the article detail page, the cover image (Logo) and thumbnail (Thumb) are the most common image elements.They are usually used to represent the main visual content of an article and are widely used on list pages

2025-11-08

How to get and display the list of tags and links associated with the article in the template?

In website operation and content management, article tags (Tag) are key tools for improving content organization, user experience, and search engine optimization (SEO) effects.They can not only help users quickly find relevant content of interest, but also provide clearer content theme information for search engines, thus improving the overall performance of the website.AnqiCMS as an efficient content management system provides intuitive template tags, allowing you to easily obtain and display the list of associated tags and links in the template.

2025-11-08

How to display custom additional field data in the article model to achieve flexible content display?

In Anqi CMS, the flexibility of content is one of its core strengths.We often need to display unique information beyond standard fields such as product SKU codes, publication dates, author information, or specific time and location of events.This personalized data, through the custom additional field feature, can achieve perfect carrying and management.But how to beautifully and flexibly present these meticulously entered custom data on the front end of the website is a focus of many users.This article will guide you to deeply understand the display mechanism of custom fields in Anqi CMS

2025-11-08

How to retrieve and display the name, description, link, and subordinate category list of a specified category?

In AnQiCMS, effective management and display of website categories are crucial for enhancing user experience and content organization.Whether it is to build a navigation menu, sidebar content, or display a category structure on a specific page, it is a common requirement to flexibly obtain the name, description, link, and list of subcategories under the category.This article will introduce how to use AnQiCMS template tags to easily achieve these functions.

2025-11-08