Content timeliness: How to intelligently display 'newly released' and 'expired' in AnQiCMS templates

Exploring the time wisdom of AnQiCMS: The intersection of documents and current time

AnQiCMS as an enterprise-level content management system, provides high flexibility in building content models, including fine-grained management of document time attributes.Every document published through AnQiCMS has its "publish time" accurately recorded by the system.archiveDetailTag easily retrieves this core data.

Specifically, when we use it on the document details page or list page.archiveDetailWhen the tag retrieves document information.CreatedTimeThe field carries the publication time of the document, presented in the form of a Unix timestamp (10 digits, representing the number of seconds since 00:00:00 UTC on January 1, 1970).This is the foundation on which we perform time comparison.

To determine the timeliness of the content, we also need to obtain the current real-time time. Although it is in the template environment of AnQiCMS,{% now "2006-01-02 15:04:05" %}Labels can help us format and display the current date and time, but what we need for direct numerical comparison is the current Unix timestamp. Typically, CMS systems like AnQiCMS provide a global variable in the template context that can be used directly to obtain the current Unix timestamp, for example, many template engines assume that ancurrent_unix_timestampSuch a variable, it is also a 10-digit number.If your AnQiCMS template environment does not provide it directly, you may need to inject it into the template context through custom template functions or backend logic.

Through mastering these two time dimensions——theCreatedTimeand the current Unix timestamp, we can build a logical framework for judging the timeliness of content.

Core logic construction: Define the lifecycle of content

To achieve intelligent display of 'new release' and 'expired', we need to clarify two time points:

  1. Definition of 'new release'This period refers to a short time after the document is published, such as 3 days, 7 days, or within 1 month. The content within this period is considered the most recent and deserves special attention.
  2. Definition of 'Expired':指文档发布时间已久,例如半年、一年甚至更长时间后,其内容可能不再完全适用,或者我们希望鼓励用户查阅更新的信息。

These 'days' or 'months' eventually need to be converted to seconds to compare numerically with Unix timestamps. For example:

  • One day = 24 hours * 60 minutes/hour * 60 seconds/minute = 86400 seconds
  • Three days = 3 * 86400 seconds
  • One year = 365 * 86400 seconds (simplified, leap years are not considered)

With these time difference definitions, we can use them in templatesifLogical judgment tag for conditional branching, based on the difference between the current timestamp and the document publishing timestamp to determine which state to display.