How to display the publication time of articles in the AnQiCMS template and customize the format?

Calendar 👁️ 75

In website content operation, the publication time of the article is a seemingly simple but crucial detail.It not only affects users' judgments on the timeliness of content, but is also an important reference factor for search engines to evaluate content freshness and ranking.For AnQiCMS users, being able to flexibly display and customize the publication time of articles in templates is a basic operation to enhance website user experience and SEO performance.

AnQiCMS as an efficient and customizable content management system, provides a very friendly template engine, allowing you to easily control the way content is displayed.Display the publication time of the article and customize its format, which is achieved by using its template tags and filters.

Get the publication time of the article: Basic fieldCreatedTimewithUpdatedTime

Firstly, we need to understand how the publishing time of the article is stored in AnQiCMS. In the document model of AnQiCMS, each article is built-in withCreatedTime(creation time) andUpdatedTime(Update time) These fields. When you publish or edit articles in the background, these times will be automatically recorded.

In the AnQiCMS template, whether througharchiveListTag to loop display article list or use it on the article detail pagearchiveDetailTag to get information of a single article, you can access these time fields. For example, when you are in an article loop,itemRepresents the current article object, so its publication time isitem.CreatedTime; If on the article detail page,archiveRepresents the current article object, its publication time isarchive.CreatedTime.

Output directly in the template{{archive.CreatedTime}}or{{item.CreatedTime}}When you find it, it displays a series of numbers, which is what is called a timestamp.A timestamp is usually the number of seconds that have elapsed since a fixed point in time (such as January 1, 1970, 0:0:0) to the current time.Although machines can understand this format, it is not intuitive for visitors.Therefore, we need to convert it to an easily readable date and time format.

Custom time format:stampToDateMagic of tags

AnQiCMS provides a very practical template tag for this——stampToDate. This tag's 'magic' lies in its ability to easily convert the original timestamp into any date and time format you want.

stampToDateThe usage method of the tag is very intuitive:{{stampToDate(时间戳, "格式")}}. The 'timestamp' mentioned earlier is this.archive.CreatedTimeoritem.CreatedTimeThe field value. The "format" parameter is its core secret, which follows the time formatting rules of the Go language (the development language of AnQiCMS).

The date formatting rule in Go language is different from other programming languages (such as PHP or Python). It does not useY-m-dor%Y-%m-%dThis placeholder is instead with a specific reference date and time as a template:2006-01-02 15:04:05. You need to replace the numbers in this reference date with the format you want to see in the final output.

For example:

  • To display the full year (2006), use2006.
  • To display the two-digit month (01), use01.
  • To display the two-digit date (02), use02.
  • Use to display the hour (15) in 24-hour format15.
  • Use to display the minute (04)04.
  • Use to display the second (05)05.

Through this reference template, you can flexibly combine various formats:

  • Only display the date (year-month-day): {{stampToDate(archive.CreatedTime, "2006-01-02")}}
  • Display Chinese date: {{stampToDate(archive.CreatedTime, "2006年01月02日")}}
  • Display date and time: {{stampToDate(archive.CreatedTime, "2006-01-02 15:04")}}
  • Only display time: {{stampToDate(archive.CreatedTime, "15:04")}}
  • Show Abbreviated English Month Names: {{stampToDate(archive.CreatedTime, "Jan 02, 2006")}}
  • Show the day of the week: {{stampToDate(archive.CreatedTime, "Mon Jan 02 2006")}}

Practice in the template: Show publish time

Next, let's see how to apply it in the actual templatestampToDate.

1. Show publish time on the article detail page

In the article detail page (for examplearchive/detail.htmlOr a custom article template), you would typically access the current article object directlyarchiveYou can display the publish time like this:

<article>
    <h1>{{ archive.Title }}</h1>
    <p>
        发布于:{{ stampToDate(archive.CreatedTime, "2006年01月02日 15:04") }}
        {%- if archive.UpdatedTime and archive.UpdatedTime > archive.CreatedTime %}
        (更新于:{{ stampToDate(archive.UpdatedTime, "2006年01月02日 15:04") }})
        {%- endif %}
    </p>
    <div>
        {{ archive.Content|safe }}
    </div>
</article>

In the code snippet above, we first displayed the article'sCreatedTime. Then, we added a conditional judgment: ifUpdatedTimeexists and is later thanCreatedTime, then display the "Updated at" time, so that visitors can understand the latest status of the content. Here|safeThe filter is used to ensure that HTML tags in the article content are parsed and displayed correctly.

2. Display the publish time on the article list page.

In the article list page (for examplearticle/list.htmlOr a custom category list template, you usually usearchiveListTags to loop through multiple articles. Inside the loop body,itemThe variable represents each article.

<ul class="article-list">
    {% archiveList archives with type="page" limit="10" %}
        {% for item in archives %}
        <li>
            <h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
            <p class="meta">
                发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}
                <span>浏览量:{{ item.Views }}</span>
            </p>
            <p>{{ item.Description }}</p>
            <a href="{{ item.Link }}" class="read-more">阅读更多</a>
        </li>
        {% empty %}
        <li>目前还没有文章发布。</li>
        {% endfor %}
    {% endarchiveList %}
</ul>

In this example, the publication time of each article is displayed below the title in a concise "Year-Month-Day" format, helping users to quickly browse.

More custom formats and practical skills

MasterstampToDateTags and Go language's time formatting rules, you will have unlimited customization capabilities. You can try:

  • Internationalized date format:If your website is aimed at global users

Related articles

How does AnQiCMS control the display of content in different areas through the 'Flag' attribute (such as recommended, headline)?

## AnQiCMS: How to make good use of the "Flag" attribute to accurately control the layout of website content In content operation, it is not enough to just publish articles.How to make important content stand out, how to intelligently display specific content in different areas of the website, is the key to improving user experience and operational efficiency.AnQiCMS is well-versed in this field and has provided us with a powerful and flexible tool - the 'Flag' attribute, to巧妙ly achieve this goal.What is the content "Flag" attribute?In short

2025-11-08

How to enable Markdown editor and correctly render mathematical formulas and flowcharts in AnQiCMS?

Enable the complete guide to Markdown, rendering mathematical formulas and flowcharts in AnQiCMS AnQiCMS, as an efficient and flexible content management system, has been striving to provide more convenient and powerful content editing and display capabilities for content creators.For those who often need to write technical documents, academic papers, or explanations involving complex logic processes, the original rich text editor sometimes feels inadequate.

2025-11-08

How to display related article lists in AnQiCMS to enhance user browsing?

In content operations, guiding users to continuously explore within the site, extending their stay time, is one of the key strategies to improve user experience and website conversion rates.The list of relevant articles is an efficient tool to achieve this goal.AnQiCMS as a high-performance, flexible content management system provides various ways to cleverly display related articles, thereby deeply tapping into the browsing potential of users.Why is the related article list so important?

2025-11-08

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

When visitors browse articles on a website, they often hope to be able to jump to related content conveniently, especially the previous or next one.This design not only improves the user experience, but also has a positive impact on the internal link structure of the website and search engine optimization.AnQiCMS fully considered such user needs, built in simple and efficient template tags, helping us easily implement the previous and next article link function on the article detail page.

2025-11-08

How to retrieve and display single-page content in AnQiCMS, such as "About Us"?

In website operation, pages like "About Us" and "Contact Information" are indispensable components. They usually carry relatively fixed and important content such as corporate culture, contact information, and service introduction.For users of AnQiCMS, obtaining and displaying these single-page contents is not only simple and efficient but also highly flexible and customizable.This type of independent page, with content that does not change often, is classified as "single page" by Anqi CMS, and a dedicated management module is provided in the background for easy creation, editing, and publishing by users.

2025-11-08

How to manage and display the list of friend links in AnQiCMS?

Friend links are an important part of website optimization and user experience, they can not only help your website rank better in search engines, but also provide visitors with more valuable resources, and also serve as a bridge to establish contact with industry partners.In AnQiCMS, managing and displaying friend links is a straightforward and flexible operation, allowing you to easily configure these important external connections for your website. ### Back-end Management Friend Links List To start managing friend links, you need to log in to the AnQiCMS back-end.All auxiliary functions are concentrated under the 'Function Management' menu

2025-11-08

How to implement unified management of multi-site content and front-end display in AnQiCMS?

In the current complex and variable network environment, whether it is a large and medium-sized enterprise with multiple sub-brands and business lines, or a self-media operator that needs to create independent content platforms for different audience groups, how to efficiently manage multiple websites and ensure the flexibility and consistency of front-end content display has become a core challenge in content operation.The traditional 'one website, one system' model not only increases the cost of deployment and maintenance, but also makes content collaboration and data analysis extremely complicated.AnQiCMS (AnQi Content Management System) is precisely in such a context

2025-11-08

How to display breadcrumb navigation in AnQiCMS template to optimize user experience?

Have you ever felt lost while browsing a website?On an information-rich website, users sometimes feel overwhelmed, not knowing their current location, and it is also difficult to quickly backtrack to the upper page.This Breadcrumb Navigation is like a guiding light, providing clear path guidance and greatly optimizing their website experience.Breadcrumb navigation is usually displayed in the form of "Home > Category > Subcategory > Current Page", which can help users clearly understand their position in the website structure

2025-11-08