How to determine the relationship between the current time and the document publishing time in the AnQiCMS template, and display "New" or "Expired"?

Calendar 👁️ 72

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.

Related articles

How to conditionally use the `cycle` tag to alternate CSS classes within a `for` loop?

## How to conditionally use the `cycle` tag elegantly in the `for` loop of AnQiCMS?In website content display, especially on list pages, we often hope to enhance user experience and information readability through visual differences.For example, list rows alternate with different background colors, or certain types of list items require special styles to highlight.As an experienced website operations expert, I am well aware of the efficient and flexible content management system in AnQiCMS

2025-11-06

How to determine if the `Logo` field of `tagDetail` exists to display the cover image of the label?

As an experienced website operations expert, I know that how to flexibly and elegantly handle content display is the key to improving user experience and the professionalism of the website.Today, let's talk about how to cleverly judge whether the `Logo` field exists in the tag details of AnQiCMS (AnQiCMS), and decide whether to display the cover image of the tag.This is not just a technical implementation issue, but also about how we make the tabs more attractive.### Label cover image: The highlight of content operation In AnQi CMS

2025-11-06

How to determine if the document list under a specified tag is empty?

AnQi CMS, as an enterprise-level content management system built with Go language, has always been committed to providing users with efficient, customizable, and secure content operation solutions.In our daily content management work, especially when building dynamic, intelligent websites, we often need to flexibly adjust the display of the page based on the presence or absence of content.Today, let's delve deeply into a very practical and elegant feature of Anqi CMS - how to use the `tag-tagDataList` tag to determine if the document list under a specified tag is empty.In AnQi CMS

2025-11-06

How to display different fields in `moduleDetail` based on model type (such as `article model` or `product model`)?

Deep analysis of AnQi CMS: How to display different fields in `moduleDetail` based on model type to create a personalized content experience As a senior website operation expert, I know that a truly excellent content management system is not just about publishing content, but also needs to be flexible to adapt to various content forms.AnQiCMS (AnQiCMS) performs exceptionally well in this aspect, its powerful 'content model' function is the secret weapon for us to achieve personalized content display.

2025-11-06

How to conditionally generate a URL based on the settings of `BaseUrl` or `MobileUrl` in the `tag-system` tag?

## Precise Targeting: How to generate URL based on `BaseUrl` or `MobileUrl` conditions in AnQi CMS?In today's multi-screen interconnected era, providing users with smooth and device-adaptive content experience is the key to the success of website operation.Whether it is on the PC side or the mobile side, we hope that users can access the page that is most suitable for their device.AnQi CMS, this enterprise-level content management system developed based on the Go language, with its efficient and flexible features, provides powerful tools for content operators to meet this challenge.Today, as an experienced website operation expert

2025-11-06

How to use `if` judgment in AnQiCMS template to prevent rendering errors caused by undefined variables?

## Mastering AnQi CMS Template: Skillfully use `if` statements to say goodbye to undefined variable rendering errors!As a senior website operation expert, I am well aware of the importance of a stable and efficient website template for user experience and operation efficiency.AnQiCMS (AnQiCMS) offers powerful support for content management with its efficient architecture based on the Go language and a flexible Django-like template engine.However, even the most excellent system may cause rendering errors due to minor omissions in the template, the most common of which is accessing undefined variables. Today

2025-11-06

How to skip a specific `Id` page and not display it when looping through a single page `tag-pageList`?

## Masterfully Control Content Display: AnQi CMS `tag-pageList` Skipping Specific Pages As an experienced website operations expert, I am well aware of the importance of the flexibility of the content management system for operational efficiency and user experience.AnQiCMS (AnQiCMS) provides us with powerful content management capabilities with its high-performance architecture based on the Go language.

2025-11-06

In AnQiCMS template, how to determine if the date format converted by `stampToDate` is correct or valid?

In the vast realm of content management and website operation, every detail concerns the user experience and the accuracy of information transmission.The accurate display of date and time is an indispensable part of it.For operators and developers using AnQiCMS to build websites, how to elegantly handle timestamps in templates and ensure their correct and effective format is a topic worth in-depth discussion.Today, let's talk about the philosophy and practical wisdom of using the `stampToDate` tag in the AnQiCMS template.### Know

2025-11-06