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.