How to get the release (CreatedTime) or update time (UpdatedTime) of the previous document using the `prevArchive` tag?

Calendar 👁️ 71

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.

Related articles

In AnQi CMS, how can the `Id` field of the previous document be retrieved through the `prevArchive` tag?

As an old soldier who has been deeply involved in website operation for many years, I know that how to efficiently obtain and utilize content data in a content management system is crucial for improving user experience and website maintenance efficiency.AnQiCMS (AnQiCMS) boasts its concise and efficient features, providing many intuitive template tags to make content operation more flexible.Today, let's delve into a very practical scenario: how to retrieve the `Id` field of the previous document in AnQiCMS using the `prevArchive` tag.###

2025-11-07

What are the similarities and differences in the functionality between the `prevArchive` and `nextArchive` tags?

As an experienced website operation expert, I know how crucial it is to skillfully utilize each feature point in a high-efficiency content management system like AnQiCMS to optimize user experience and content management efficiency.Today, let's delve into the two navigation tools in Anqi CMS template tags that seem similar but have different missions: the `prevArchive` tag and the `nextArchive` tag, analyze their similarities and differences in function, and help you build a smooth website browsing experience.###

2025-11-07

How to use the `prevArchive` tag to display the thumbnail or cover image of the previous document?

## Enhance Content Relevance: Use the `prevArchive` tag in AnQiCMS to display the thumbnail or cover image of the previous document In today's increasingly fragmented content consumption, how to effectively guide users to browse more content, improve the stay time on the website, and enhance the user experience is a problem that every website operator needs to think deeply about.AnQiCMS as a highly efficient and customizable enterprise-level content management system provides many powerful template tags, making content operation and display extremely flexible. Today

2025-11-07

The `prevArchive` tag supports which parameters to filter or specify the previous document (the document mentions that no parameters are supported, but users may still ask)?

In AnQiCMS template development, the `prevArchive` tag is a very practical tool that can easily help us implement the navigation function of the "previous article" document on the article detail page, thereby optimizing the user's browsing experience.As a website operations expert, I fully understand the importance of smooth page transitions and convenient content discovery for user retention and SEO.However, whether the `prevArchive` tag supports parameters to filter or specify the previous document is often a question many users have when exploring the features of AnQiCMS

2025-11-07

Can you get the views (Views) information of the previous document through the `prevArchive` tag?

## Deep Dive into AnQi CMS: Can the `prevArchive` tag retrieve the page views of the previous document?As an expert in website operations for many years, I know that every CMS system is crucial in terms of content management and data presentation.AnQiCMS (AnQiCMS) boasts its high efficiency and flexibility, and has been favored by many small and medium-sized enterprises and content operators.

2025-11-07

`prevArchive` label outside the article detail page (such as the list page) whether it can still effectively obtain the previous document?

## Deep Dive into the `prevArchive` tag of Anqi CMS: The Mystery of the 'Previous' on List Pages As an experienced website operations expert, I am well aware that in daily content management, every tag and every function contains the potential to improve user experience and operational efficiency.AnQiCMS, with its simple and efficient features and SEO-friendly characteristics, has become a powerful assistant for many small and medium-sized enterprises and self-media operators.

2025-11-07

How to add custom CSS styles or HTML attributes to the link generated by the `prevArchive` tag?

As an experienced website operations expert, I am well aware of the importance of meticulous template customization in content management systems for enhancing user experience and the overall style of the website.AnQiCMS (AnQiCMS) provides us with great flexibility with its efficient architecture based on the Go language and a Django-like template engine.Today, let's delve into a common customization requirement: how to add custom CSS styles or HTML attributes to the link generated by the `prevArchive` tag for the 'previous article'.

2025-11-07

The document for the previous archive tag is determined by what logic or sorting rules?

## Unveiling the Anqi CMS `prevArchive` tag: The intelligent sorting logic of the "Previous" document As an experienced website operations expert, I know that behind each CMS tag lies the potential to enhance user experience and SEO efficiency.AnQiCMS (AnQiCMS) is known for its efficiency and flexibility, and its template tag system is an extremely powerful tool for content operations.Today, let's delve into a seemingly simple but actually cleverly logical tag: `prevArchive`, and how it intelligently determines what we mean by 'previous document'

2025-11-07