Use cleverlyprevArchiveLabel: Deeply explore the mysteries of the time in the previous document of AnQi CMS
As an experienced website operation expert, I am well aware that the timeliness and update frequency of content are crucial for the SEO performance and user experience of a website.In AnQiCMS (AnQiCMS), we often need to provide "Previous" and "Next" navigation on article detail pages, which is not only convenient for users to browse but also a good method to build internal links and improve page weight.Today, let's delve deeperprevArchiveLabel, especially how to flexibly obtain the release of the previous document (CreatedTime) or update time(UpdatedTimePresent it in an easy-to-read format on your website.
In AnQi CMS,prevArchiveTags are a very practical tool, allowing you to easily access the document data preceding it in the current document context. Their usage is simple and straightforward, usually you just need to declare a variable in the template, for example{% prevArchive prev %}. ThisprevThe variable will then carry various information from the previous document, including document ID, title, link, etc.
However, unlike directly displaying the document title or link, the time information is inprevArchiveThe tag is provided in the original Unix timestamp (timestamp) form, specifically throughprev.CreatedTimeandprev.UpdatedTimeThese fields are obtained. These timestamps are the number of seconds elapsed since 00:00:00 UTC on January 1, 1970, and such a number sequence is difficult to understand for ordinary users.
To convert these original timestamps into the daily readable date format, AnQi CMS provides a very convenient built-in feature -stampToDateLabel. This label is used to format timestamps, it requires two parameters: the first is the timestamp you want to format, and the second is the date and time format you expect to output.It is worth mentioning that Anqi CMS follows the unique date formatting rules of the Go language, using a fixed reference date2006-01-02 15:04:05Define the format. This means that if you want to display "Year-Month-Day", you enter2006-01-02; If you want to display "Hour:Minute", you enter15:04and so on.
Now, let's demonstrate how to retrieve and format the publication or update time of the previous document with several practical examples.
Assuming we want to display the title and publication date of the previous article at the bottom of the article detail page, we can write the template code like this:
{% prevArchive prev %}
{% if prev %}
<p>上一篇:
<a href="{{ prev.Link }}">{{ prev.Title }}</a>
(发布于:{{ stampToDate(prev.CreatedTime, "2006年01月02日") }})
</p>
{% else %}
<p>没有更早的文章了。</p>
{% endif %}
{% endprevArchive %}
In this code, we first use{% prevArchive prev %}To get the previous document. Then, through{% if prev %}Check if the previous document exists to avoid displaying errors when there is no previous one. The core part lies in{{ stampToDate(prev.CreatedTime, "2006年01月02日") }}, where we willprev.CreatedTime(the timestamp of the previous document's release) pass instampToDateand specified the format as "2006-01-02", so that it is displayed in the form of "XXXX year XX month XX day".
If you are more concerned about the latest updates of the document, and want to display the update time of the previous document, justCreatedTimeReplaceUpdatedTimeAnd it can also be adjusted in format as needed, for example, to display a specific time format:
{% prevArchive prev %}
{% if prev %}
<p>上一篇:
<a href="{{ prev.Link }}">{{ prev.Title }}</a>
(最后更新:{{ stampToDate(prev.UpdatedTime, "2006-01-02 15:04:05") }})
</p>
{% else %}
<p>没有更早的文章了。</p>
{% endif %}
{% endprevArchive %}
This way, your users can clearly see the detailed release or update time of the previous document, which is very helpful for judging the freshness of the content or finding the latest relevant information.In content operation strategy, clearly displaying time information can not only enhance the authority of the website content, but also indirectly encourage users to explore more updated content, and improve the overall user stickiness.
In summary, of Anqi CMS'sprevArchiveLabel combinationstampToDateThe formatting feature provides a flexible and powerful way to handle and display the time information of the previous document.Whether it is an update time accurate to the second or a concise release date, it can be realized through simple template code, making your website content operation more refined.
Frequently Asked Questions (FAQ)
Q1:nextArchiveDoes the tag also support obtaining the publishing or update time of the next document in the same way?A1: Yes,nextArchivewith the tag andprevArchiveThe function and usage of the tag are very similar. You can use it to{% nextArchive next %}to get the data of the next document, and then usenext.CreatedTimeandnext.UpdatedTimefield, and combinestampToDatethe tag for formatting, for example{{ stampToDate(next.CreatedTime, "2006-01-02") }}.
Q2: If the current document is the first in the category, thenprevArchiveWhat will the tag return? How should I handle this situation?A2: If the current document is the first article in its category, that is, there is no previous document, thenprevArchiveA variable defined by the tag (for exampleprevIt will be empty. To avoid template rendering errors, you should always use conditional judgments (such as{% if prev %}...{% else %}...{% endif %}To check if the previous document exists before displaying the content, just like we do in the article examples.
Q3: In addition to the publication or update time, can I also useprevArchiveWhat other information can the tag retrieve from the previous document?A3:prevArchiveThe tag can provide various pieces of information from the previous document, allowing for flexible use in templates. In addition,CreatedTimeandUpdatedTimeit also supports retrieving the document ID (Id), Title (Title) and link (Link) Keywords (Keywords), Description (Description), Category ID (CategoryId), Page views (Views), Cover main image (Logo), Cover thumbnail (Thumb), Number of comments (CommentCount) and so on. You can customize it according to your actual needs, byprev.字段名Call these data in the form.