轻松掌握安企CMS:文章发布与互动数据展示全攻略
In website operation, clearly displaying the publication and update time of articles, popularity (page views), and reader feedback (comment count) can not only effectively improve user experience but also enhance the authority and timeliness of the content.The AnQiCMS (AnQiCMS) takes advantage of its flexible template tag system, making it easy and efficient to obtain and display this key information.This article will explain in detail how to implement these functions in the AnQi CMS.
一、文章详情页面的数据获取
When you browse a specific article, you hope to see its publishing time, the latest update time, how many times it has been read, and how many comments there are. Anqi CMS providesarchiveDetailLabel, this is a powerful tool for obtaining detailed information of a single article.
1. Get the publication time of the article (CreatedTime)
The publication time of the article records the time when the content was first launched. In Anqi CMS,archiveDetailLabels can easily obtain this information. Since it returns a timestamp, we need to cooperatestampToDatelabels to format it into a readable date and time.
For example, if you want to display the publication date of the article, you can use the following code:
发布时间:{{ stampToDate(archive.CreatedTime, "2006-01-02") }}
Here are the"2006-01-02"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 like this:
发布时间:{{ stampToDate(archive.CreatedTime, "2006-01-02 15:04:05") }}
2. Get article update time (UpdatedTime)
The update time of the article is very important to the reader, as it indicates whether the content is up-to-date. The method to obtain the update time is similar to that of the publish time, and it also requires the use ofarchiveDetailTags andstampToDate.
更新时间:{{ stampToDate(archive.UpdatedTime, "2006-01-02 15:04:05") }}
Suggest displaying both the publishing time and the update time in the template, or only showing the update time when the content of the article is updated, to avoid redundancy.
3. Get the article view count (Views)
The number of page views of an article is a direct indicator of its popularity. AnQi CMS will automatically count the number of page views for each article andarchiveDetailprovide tags for you.
浏览量:{% archiveDetail with name="Views" %}
or, if you have already obtained the current article object througharchivevariables, you can use a more concise way directly:
浏览量:{{ archive.Views }}
4. Get the number of article comments (CommentCount)
The comments from readers are a manifestation of the interactivity of the article. The Anqi CMS.archiveDetailTags also include the function of obtaining the total number of comments, which is convenient for you to display the discussion热度 of the article.
评论数量:{% archiveDetail with name="CommentCount" %}
Similarly, in the already obtainedarchiveVariables can also be used in this case.
评论数量:{{ archive.CommentCount }}
II. 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 is cycled out. InarchiveListThe loop body, each article item will be provided to you as aitemvariable, and you can access and display the data in aarchiveDetailsimilar manner.
The following is a comprehensive example showing the publication time, view count, and comment number in the 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 %}
在这个例子中,我们通过item.CreatedTime/item.UpdatedTime/item.Viewsanditem.CommentCountAccessed the corresponding data of the current looped article. Particularly, through{% if item.UpdatedTime != item.CreatedTime %}The condition judgment ensures that only the actual updated article content will display the update time, avoiding information redundancy.
Three: Tips to improve user experience.
- 美化样式:Using CSS to format and beautify this information, such as using icons (eye icon for page views, speech bubble for comments) or different colored fonts to make it more attractive.
- Condition display:For the number of comments, if it is 0, you can choose not to display the comment count, or display "No comments" to enhance 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.
Through the above methods, you can easily present the key dynamic data of the article on the website built with Anqi CMS to your readers, making your content more vibrant.The strong template tag system of Anqi CMS allows you to have great freedom and convenience in content operation and front-end display.
Common Questions (FAQ)
Q1:Why does the article's publish time or update time show a long number instead of a specific date and time?A1:This is usually because you have directly outputedCreatedTimeorUpdatedTimeVariables, 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 usestampToDateFormat template tags, for example,{{ stampToDate(item.CreatedTime, "2006-01-02 15:04:05") }}.
Q2: Does the data of the article view count update in real time, and where is it counted?A2:The Safe CMS is built-in with traffic statistics function, the article page view data is usually updated in real-time or nearly real-time.This data will be displayed in the "Data Statistics" module on the backend. You can go to the backend to view more detailed traffic analysis and spider monitoring reports to help you understand the performance of the website.For scenarios with particularly high concurrency, CMS may adopt certain caching strategies to alleviate database pressure, but the displayed data on the front-end will still maintain a relatively high timeliness.
Q3: How many comments are displayed in my article as 0, but there are actually comments in the background? This is why?A3:Please check the background comment management module to confirm whether these comments have been approved.The autoCMS defaults to only counting and displaying the number of approved comments.Comments that are pending approval, 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 set to 'Approved' to display normally.