How to display the publish time and update time of articles in AnQiCMS templates?

Calendar 👁️ 71

Understand the publication and update time of an article, for readers, it not only helps to judge the timeliness of the content and avoid outdated information, but also is an important consideration for search engine optimization (SEO).AnQiCMS as an efficient content management system, provides flexible template features, allowing you to easily display these key time information on your website.

AnQiCMS's template system uses syntax similar to Django, it is through double curly braces{{变量}}output the value of the variable, while logical control (such as conditional judgment, loop, etc.) is used{% 标签 %}structure. In AnQiCMS, the publishing time of the article (CreatedTimeAnd update time(UpdatedTimeTimestamps are stored in the form. To convert these timestamps into the date and time format we are familiar with, AnQiCMS provides a very useful built-in tag:stampToDate.

Display the publication and update time on the article detail page

When you are browsing the detail page of a single article, you will usually usearchiveDetailLabel to get the detailed information of the current article. This label is very powerful and can directly access various attributes of the article.

To display the publication time of the article, you can use the following method:

发布时间:{{ stampToDate(archive.CreatedTime, "2006-01-02 15:04") }}

Herearchive.CreatedTimeThis is the timestamp of the current article's publication.stampToDateThe second parameter of the tag"2006-01-02 15:04"It is a formatted string that tells the system the format you want the time to be displayed as 'Year-Month-Day Hour:Minute'.

Similarly, to display the update time of the article, you can do it like this:

更新时间:{{ stampToDate(archive.UpdatedTime, "2006-01-02 15:04:05") }}

archive.UpdatedTimeRepresents the update timestamp of the article. You can see that by adjusting the formatting string, you can flexibly control the time display to seconds.

Displays the publish time and update time on the article list page.

On the article list page, you will usearchiveListLabel combinationfora loop to display multiple articles. In this case,CreatedTimeandUpdatedTimeit will be used as the attribute of each article object inside the loop (usually named)item).

For example, if you have a list of articlesarchivesyou can iterate through and display the time of each article:

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
    <article>
        <h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
        <p>
            发布于:{{ stampToDate(item.CreatedTime, "2006年01月02日") }}
            {% if item.UpdatedTime > item.CreatedTime %}
            (最后更新:{{ stampToDate(item.UpdatedTime, "2006-01-02") }})
            {% endif %}
        </p>
        <p>{{ item.Description }}</p>
    </article>
    {% endfor %}
{% endarchiveList %}

In this example, we also added a simple judgment, only whenUpdatedTimelater thanCreatedTimeOnly when, the update time is displayed, this can avoid repeating the same time in the case that the article has never been updated.

Time formatting options detailed explanation

stampToDateThe core of the label lies in its formatting parameters. This parameter follows the unique time formatting rules of the Go language, which is not traditional.Y-m-dor%Y-%m-%dInstead, use a specific date as a reference template: "2006-01-02 15:04:05.You just need to remember this reference template, and then replace the date/time part you want to display with the corresponding number in the reference template.

Here are some commonly used formatting examples:

  • Date (Year-Month-Day): "2006-01-02"
  • Date (Year/Month/Day): "2006/01/02"
  • Complete date and time (to seconds): "2006-01-02 15:04:05"
  • Date and time (to minutes): "2006-01-02 15:04"
  • Time only (Hour:Minute): "15:04"
  • Date in Chinese: "2006年01月02日"
  • Date and time in Chinese: "2006年01月02日 15时04分"

Comprehensive example

Here is an example of a template snippet that integrates the publish time and update time into the article display, giving you a more intuitive understanding of how it is applied on the actual page:

<div class="article-meta">
    <h1>{{ archive.Title }}</h1>
    <p class="time-info">
        <span>发布时间:{{ stampToDate(archive.CreatedTime, "2006年01月02日 15:04") }}</span>
        {% if archive.UpdatedTime > archive.CreatedTime %}
        <span>最后更新:{{ stampToDate(archive.UpdatedTime, "2006年01月02日 15:04") }}</span>
        {% endif %}
    </p>
    <div class="article-content">
        {{ archive.Content|safe }}
    </div>
</div>

By using the above method, you can easily and flexibly display the publication and update time of articles in AnQiCMS templates, which not only improves user experience but also lays a good foundation for the website's SEO performance.


Frequently Asked Questions (FAQ)

Q1: Why is the time displayed as a long number instead of a date format?A1: This is usually because you forgot tostampToDateProvide the second parameter in the tag, which is the time formatting string.CreatedTimeandUpdatedTimeIt is a timestamp and needs to be converted throughstampToDateto a readable date and time format. Make sure your code is similar.{{ stampToDate(item.CreatedTime, "2006-01-02") }}of which"2006-01-02"Is the format you expect.

Q2: Can I make the publish time only show the date and the update time show to the second? Can this be done?A2: Of course.stampToDateThe flexibility of the label is manifested in its formatting parameters. You can use this format for publish time"2006-01-02"and this format for update time"2006-01-02 15:04:05"This format, the system will convert according to your settings separately.

Q3: What will be displayed as the update time if the article has never been updated?A3: In AnQiCMS, if an article has never been manually updated, itsUpdatedTimefield will usually beCreatedTimethe same. Therefore, if you display it directlyUpdatedTimeIt will be consistent with the release time. To provide a better user experience, you can add a conditional judgment as shown in the article list page example ({% if item.UpdatedTime > item.CreatedTime %}Only when the update time is indeed later than the release time, will the word "Last Updated" be displayed.

Related articles

How does AnQiCMS implement intelligent recommendation and display of related articles?

In content operation, effectively recommending relevant articles to readers can not only significantly increase user stay time and page views, but also indirectly promote search engines to crawl and allocate weights to the website's content through internal link optimization.AnQi CMS is well-versed in this, providing a smart and flexible mechanism to help users easily implement the recommendation and display of related articles.How does AnQiCMS implement intelligent article recommendation?

2025-11-08

How to display the links and titles of the previous and next articles on the article detail page?

When a reader visits an article of interest, they often hope to browse related or continuous content seamlessly, rather than returning to the list page to search again.Provide navigation links to "Previous" and "Next" articles on the article detail page of the website, which is an effective way to enhance this reading experience and increase user stickiness.It can not only guide users to explore the website content in depth, but also optimize the internal link structure of the website to a certain extent, making it friendly to search engines.AnQiCMS (AnQiCMS) is a powerful content management system that fully considers the needs of content operation

2025-11-08

How to call and display custom field content in the article detail page of AnQiCMS?

In AnQiCMS, managing and displaying content, custom fields play a crucial role, enabling our website to flexibly carry various unique information, not limited to common attributes such as titles and content.Whether it is to add detailed technical parameters for product detail pages or to supplement author biographies and external reference links for articles, custom fields can provide strong support.Understand how to call and display these custom fields on the article detail page, which will greatly enhance the richness and customization of the website content. AnQiCMS

2025-11-08

How to get and display the detailed information of a single article in AnQiCMS?

Managing and displaying content in AnQiCMS is one of its core functions.It is crucial to understand how to accurately retrieve and display the detailed content of a specific article when you need to present it to visitors.AnQiCMS provides a直观 and powerful template tag system that allows you to flexibly control the layout and content of the article detail page. ### Overview of AnQiCMS Template System The AnQiCMS template uses syntax similar to the Django template engine.In the template file, you will encounter two main markers: - **Double braces

2025-11-08

How to customize the URL static rules of the article detail page in AnQiCMS?

In website operation, a clear and friendly URL structure is crucial for search engine optimization (SEO) and user experience.AnQiCMS provides flexible URL rewriting (URL rewrite) functionality, allowing users to customize the URL format of article detail pages according to their needs.This article will introduce in detail how to customize the URL static rules for the article detail page in AnQiCMS.Why do you need to customize URL static rules?

2025-11-08

How to set the page title (Title) in AnQiCMS template and automatically append the website name?

In website operation, the page title (Title) is a crucial element, it not only directly affects the willingness of users to click in the search engine results page (SERP), but is also a key indicator for search engines to judge the relevance of page content.A clear, standardized title that includes the website brand name, which can effectively enhance the professionalism and brand recognition of the website.AnQiCMS provides a flexible and powerful mechanism for setting website titles, allowing you to easily control the title of each page and automatically attach the website name

2025-11-08

How does AnQiCMS dynamically display the page keywords (Keywords) and description (Description)?

AnQiCMS has always been committed to providing flexible and powerful functions in content management and SEO optimization, with the dynamic display of page keywords (Keywords) and descriptions (Description) being one of its core highlights.For any website that hopes to perform well in search engines, precise TDK (Title, Description, Keywords) configuration is indispensable.

2025-11-08

How to implement the display of Canonical normative links in AnQiCMS templates to optimize SEO?

In the field of website operation and Search Engine Optimization (SEO), Canonical (standard) links are a very important concept.It can help search engines identify and handle duplicate content issues on websites, ensuring that the authority and ranking of the website are not affected by scattered content.In AnQiCMS (AnQi CMS), implementing the display of canonical links is a key step in optimizing website SEO, and through its flexible template system, this process becomes intuitive and efficient.

2025-11-08