What tags does Anqi CMS provide to display content publishing or update time information?

Calendar 👁️ 83

In website content operation, the timing of content publication and update is a key factor in conveying the timeliness of information and establishing user trust.For search engine optimization (SEO), clear time information also helps improve the freshness rating of the content.AnQi CMS is well-versed in this, providing users with flexible and diverse tags and methods to accurately and beautifully display these time information on the website front-end.

Next, we will explore how Anqi CMS helps us manage and display the content publication and update time.

The core time tags for content publication and update.

AnQi CMS in content management provides two important time attributes for each document (whether it is an article, product, or other custom model content): the content'sRelease TimeandUpdate time.

  1. Publish time (CreatedTime)Every time we publish a document on the Anqie CMS backend, the system will automatically record the exact time the operation occurred.This is the initial creation time, which is the time of content release, representing the moment when the content first appeared.In the template, we can go throughCreatedTimeThis field is used to get it.

    For example, on the document detail page or document list page, you can call the publication time in the following way:

    {# 在文档详情页直接获取当前文档的发布时间 #}
    <div>发布日期:{{ archive.CreatedTime }}</div>
    
    {# 在文档列表循环中获取每篇文章的发布时间 #}
    {% archiveList archives with type="list" limit="10" %}
        {% for item in archives %}
            <div>文章标题:{{ item.Title }},发布于:{{ item.CreatedTime }}</div>
        {% endfor %}
    {% endarchiveList %}
    

    You will notice that it outputs directly.{{ item.CreatedTime }}or{{ archive.CreatedTime }}You might get a string of numbers, which is actually a Unix timestamp that needs to be further formatted to become the date and time we read in everyday life.

  2. Update time (UpdatedTime)With the continuous maintenance and improvement of the website content, we often need to modify and update the published content. AnQi CMS also records each important modification of the content and providesUpdatedTimeThe label shows the latest update time of the content. This is very important for users to understand the timeliness of the content, as well as for search engines to judge whether the content is active and fresh.

    The method of calling the update time is similar to the release time:

    {# 在文档详情页获取当前文档的更新时间 #}
    <div>最后更新:{{ archive.UpdatedTime }}</div>
    
    {# 在文档列表循环中获取每篇文章的更新时间 #}
    {% archiveList archives with type="list" limit="10" %}
        {% for item in archives %}
            <div>文章标题:{{ item.Title }},更新于:{{ item.UpdatedTime }}</div>
        {% endfor %}
    {% endarchiveList %}
    

    Similarly,UpdatedTimeThe default output is also a timestamp, which needs to be formatted.

A flexible time formatting tool:stampToDateTag

due toCreatedTimeandUpdatedTimePresented in the form of timestamps by default, to make this time information more readable, AnQi CMS provides a powerful template functionstampToDate. This tag can convert timestamps into various custom date and time formats.

stampToDateThe usage is very intuitive:{{stampToDate(时间戳, "格式")}}

Here, the 'timestamp' is what we get throughCreatedTimeorUpdatedTimeThe number obtained, the "format" part follows the Go language time formatting standard. Understanding the Go language time formatting may sound foreign at first, but it is very flexible, through a specific reference time2006-01-02 15:04:05Define the output format. Just replace the year, month, day, hour, minute, and second in this reference time with the display style you want.

Some commonly used formatting examples:

  • Show Date and Month {{stampToDate(item.CreatedTime, "2006-01-02")}}It will be displayed as2024-03-15
  • Show Chinese Date and Month {{stampToDate(item.CreatedTime, "2006年01月02日")}}It will be displayed as2024年03月15日
  • Display the full date and time: {{stampToDate(item.UpdatedTime, "2006-01-02 15:04:05")}}It will be displayed as2024-03-15 10:30:45
  • Show Brief Date and Month {{stampToDate(item.CreatedTime, "01-02")}}It will be displayed as03-15
  • Show Hour and Minute {{stampToDate(item.UpdatedTime, "15:04")}}It will be displayed as10:30

CombinestampToDateTags, we can display the publish and update time like this:

{# 在文档详情页显示格式化后的发布和更新时间 #}
<div>发布日期:{{stampToDate(archive.CreatedTime, "2006年01月02日")}}</div>
<div>最后更新:{{stampToDate(archive.UpdatedTime, "2006-01-02 15:04")}}</div>

{# 在文档列表页显示格式化后的发布时间 #}
{% archiveList archives with type="list" limit="10" %}
    {% for item in archives %}
        <div>
            <h3>{{ item.Title }}</h3>
            <p>发布于:{{stampToDate(item.CreatedTime, "2006-01-02")}}</p>
            <p>更新于:{{stampToDate(item.UpdatedTime, "2006-01-02")}}</p>
        </div>
    {% endfor %}
{% endarchiveList %}

Other time-related auxiliary tags and filters

In addition to the above main tags, Anqi CMS also provides some other auxiliary functions related to time:

  • Display the current server time:{% now "格式" %}If your page needs to display the current server time, for example, displaying “Copyright © 2024” in the footer, you can use{% now "2006" %}to get the current year.

    <div>版权所有 © {% now "2006" %} 安企CMS</div>
    
  • dateFilterSecurity CMS also providesdatea filter whose function is similar tostampToDateIt can format time. However, it is worth noting thatdateThe filter expects input to be in Go languagetime.TimeType variables, not timestamps. In practice, due toCreatedTimeandUpdatedTimeall being timestamps, sostampToDateit is usually more convenient to handle these fields.

Value in practical application

Reasonably display the publication and update time of content, not just a reflection of information transparency, but also a double enhancement for website SEO and user experience.Users can intuitively judge the freshness of content, especially in scenarios that require high timeliness, such as news, technical tutorials, or product reviews.At the same time, search engines will also consider the update frequency and the latest release time of the content as important ranking reference factors, which helps the website content achieve better visibility and click-through rate in search results.

In summary, Anqi CMS provides detailed support for displaying time information, from basic time data acquisition to flexible formatting tools, all of which help us better manage and present the timeliness of web content.


Frequently Asked Questions (FAQ)

1. Why do I output directly in the template{{archive.CreatedTime}}Is it a string of numbers, not a date format?The number you see is a Unix timestamp, which represents the number of seconds from January 1, 1970, 0:0:0 (UTC) to the present. To convert it to a readable date and time format, you need to use the Anqi CMS providedstampToDateThe template function is used for formatting, for example{{stampToDate(archive.CreatedTime, "2006-01-02 15:04:05")}}.

2. I want to display the publish time on both the article list and the detail page, do I need to write two different tags?Do not need. Anqi CMS has designed a unified tag call method. Whether it isarchiveListin the loopitemvariables, orarchiveDetailofarchivevariables, they all containCreatedTimeandUpdatedTimefields. You can use the samestampToDateFunctions and formatting parameters are used to display them, ensuring the conciseness and consistency of template code.

3. If I only want to display the publish date and not the specific time, how should I set it?stampToDateWhat is the format?If you only want to display the date, you can omit the hour, minute, and second parts of the Go language time format reference. For example, use"2006-01-02"You can only display the year, month and date, for example2024-03-15. If you need to display it in Chinese format, you can use"2006年01月02日".

Related articles

How to judge conditions in templates and dynamically display different content blocks based on logic?

In AnQiCMS, flexibly controlling the display of web page content is the key to website operators creating personalized, high-efficiency websites.The AnQiCMS template engine provides rich logical judgment and dynamic content display capabilities, allowing us to present content intelligently according to different conditions, greatly enhancing user experience and website adaptability.AnQiCMS' template syntax is clever, it absorbs the advantages of the Django template engine while also taking into account the characteristics of the Go language.

2025-11-08

How to use the pseudo-static function of Anqi CMS to optimize the display structure of URLs and improve SEO effects?

In website operation, the structure of URL (Uniform Resource Locator) has a significant impact on the SEO performance of the website.A clear, concise, and meaningful URL not only improves user experience but also helps search engines better understand and crawl web content.AnQiCMS (AnQiCMS) is well-versed in this field, providing powerful static URL features to help us easily optimize the display structure of URLs, thereby significantly enhancing SEO effects.

2025-11-08

How to configure the display of page TDK (title, keywords, description) for search engine optimization (SEO) in Anqi CMS?

It is crucial for website operation to let search engines better understand and display our content.This configuration of page TDK (Title, Description, Keywords) plays a core role.AnQi CMS provides us with flexible and powerful TDK management functions, allowing us to accurately optimize search engine optimization according to the characteristics of different pages.Next, we will learn step by step how to configure these key TDK information in Anqi CMS.### One, Global Setting of Website Homepage TDK The website homepage is the facade

2025-11-08

How can AnQi CMS manage and display multilingual content to support international promotion?

Under the wave of globalization, does your website desire to reach a wider audience?Providing content in the native language for users of different languages can not only greatly enhance the user experience, but is also a key step in expanding into the international market.AnQiCMS (AnQiCMS) is well aware of this need, and from the very beginning of its design, it has made multilingual support one of its core features, making content internationalization simple and efficient. ### Content Organization and Presentation: Multi-site Collaboration and Language Package Support Anqi CMS provides a clear and efficient logic for managing multilingual content. First

2025-11-08

How to display the link to the previous and next article on the Anqi CMS content page?

In AnQi CMS, it is a common need to add navigation links for "Previous Article" and "Next Article" to enhance the user experience of the website and the efficiency of internal links.These links not only help visitors browse related content more smoothly, but also have a positive impact on the website's SEO performance.AnQi CMS provides a set of intuitive template tags that allow you to easily display these navigation features on the content detail page.### Core Function: Use `prevArchive` and `nextArchive` tags Anqi CMS passes through

2025-11-08

How to display a list of recommended content related to the current article?

In content operation, guiding users to discover more interesting content is one of the key strategies to enhance user experience and extend the time spent on the website.AnQiCMS (AnQiCMS) provides very flexible and powerful features, helping us easily achieve the goal of displaying a list of recommended content related to the current article.Why is it necessary to have relevant recommended content?

2025-11-08

How does Anqi CMS display and manage website friend links?

In website operation, friendship links play an important role. They not only help to improve the website's search engine ranking (SEO), but also bring valuable traffic, and are also a manifestation of cooperation and mutual trust between websites.Anqi CMS is well-versed in this, providing website operators with a直观 and efficient buddy link management and display solution, allowing you to easily master this feature.Next, we will delve into how to manage friend links in the background, to how to flexibly display them on the website frontend, and provide you with a detailed explanation of the friend links feature of Anqi CMS.

2025-11-08

How to display the list of user comments on articles in AnQi CMS?

In AnQi CMS, allowing users to comment on articles and clearly displaying these comments is an important aspect of enhancing the interactivity and user engagement of the website.AnQiCMS's powerful template engine and built-in features make this process flexible and efficient.This article will introduce in detail how to integrate the comment list and its related functions on the article detail page.

2025-11-08