Content timeliness: How to intelligently display 'New Release' and 'Expired' in AnQiCMS templates

In the ever-changing world of the Internet, the 'freshness' and 'timeliness' of content is the key to attracting and retaining visitors on the website.As an experienced website operations expert, I am well aware of the strength of AnQiCMS (AnQi Content Management System), which not only provides flexible content management capabilities, but also enables infinite display possibilities through its powerful template engine.Today, we will delve into how to cleverly judge the relationship between the current time and the document publication time in the AnQiCMS template, thereby intelligently labeling content with 'new release' or 'expired' tags to enhance user experience and content operation efficiency.

Mining 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 management of document time attributes.Each document published through AnQiCMS has its "publish time" precisely recorded by the system.On the template level, we can go througharchiveDetailThe tag easily gets this core data.

Specifically, when we use it on the document detail page or list pagearchiveDetailWhen the tag gets document information,CreatedTimeThe field carries the document's publication time, 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 compare time.

In order to judge 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" %}Tags can help us format and display the current date and time, but for direct numerical comparison, we need the current Unix timestamp. Typically, CMS systems like AnQiCMS provide a global variable in the template context that can be used to directly obtain the current Unix timestamp, for example, many template engines can assume that one existscurrent_unix_timestampsuch a variable, it is also a 10-digit number. If it is not directly provided in the AnQiCMS template environment, you may need to inject it into the template context through a custom template function or backend logic.

By mastering these two time dimensions—the document'sCreatedTimeand the current Unix timestamp, we can build a logical framework for judging the timeliness of content.

Core logic construction: defining the life cycle of content

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

  1. Definition of 'new release'This usually refers to a short period of time after the document is published, such as 3 days, 7 days, or within 1 month. The content within this period is considered the latest and deserves special attention.
  2. The definition of "expired".: Refers to a document that has been published for a long time, such as half a year, a year, or even longer, the content may no longer be completely applicable, or we hope to encourage users to check for updated information.

These 'days' or 'months' ultimately need to be converted to seconds so that they can be numerically compared 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 (This simplification does not consider leap years)

With the definition of these time difference values, we can use them in the templateifLogical judgment tag for conditional branching, decide what status to display based on the difference between the current timestamp and the document publishing timestamp.