The Practical Guide to Anqi CMSstampToDateWith HTMLdatetimeHow to give wings to your website's SEO?
As an experienced website operation expert, I know that in the increasingly fierce internet competition, every detail may become the key to a website standing out.For SEO, content quality is indeed the core, but optimization at the technical level should not be ignored either.stampToDateFormatted date, apply it to HTML'sdatetimeproperties.
Since its inception, Anqi CMS has embedded 'SEO-friendly' in its design genes.From flexible pseudo-static rules, comprehensive TDK (Title, Description, Keywords) management, to advanced SEO tools such as Sitemap generation and link submission, every aspect reflects the determination to help users achieve better visibility in search engines.On the processing of time information, AnQiCMS also provides strong support, such as its 'Time Factor - Scheduled Publishing Function', making content operation more flexible.Today we will talk about the art of 'formatting' time information on web pages, and how it communicates at a deeper level with search engines.
Identify the value of time: why do we need to treat date information specially?
Dates and times are ubiquitous elements in the content of our website, such as the publication time of articles, the time products are listed, and the deadline for events.For users, a clear and readable date can help them quickly judge the timeliness of the information; however, for search engines, text like 'October 26, 2023' may be understandable to humans, but machines may not be able to accurately interpret its inherent meaning by 100%, especially in cross-language and cross-cultural environments.
This raises a core issue: How can we ensure that the user's reading experience is maintained while also allowing search engines to accurately and error-free understand the time information on the page? The answer lies in the introduction of HTML5.<time>[en] Element and itsdatetimeproperties.
Anqi CMS'sstampToDate[en] Magic wand of timestamps
The AnQi CMS usually stores time information of dynamic content in the form of Unix timestamps. For example, when we call the document details,archive.CreatedTimeandarchive.UpdatedTimeThe field returned is a 10-digit timestamp. These original timestamps are difficult for users to understand as a sequence of numbers, so we need to format them.
This is where the template engine of AnQi CMS comes into play, providing an extremely convenient timestamp formatting tag:stampToDateThis tag is like a 'magic wand' that can convert the cold timestamp into any date and time format we need. Its usage is very intuitive:{{stampToDate(时间戳, "格式")}}.
The "format" parameter is particularly powerful, as it follows the Golang (the development language of AnQi CMS) time formatting rules, meaning you can precisely define the year, month, day, hour, minute, second, and even the day of the week in the output. For example, "2006-01-02"Can be formatted as “2023-10-26”"2006年01月02日 15:04"The format can be
HTMLdatetimeAttribute: The exclusive translator of the search engine.
HencestampToDateWe can easily display beautiful dates for users. However, to further improve SEO, we need to introduce...datetimeProperties. This property is specifically used for<time>tags, which serve to provide a machine-readable date or time format, typically followingISO 8601 standardformat.
Then, put the formatted date indatetimeWhat benefits does the attribute have for SEO?
- Enhance search engine understanding:Search engine crawlers and algorithms will read
datetimeThe standardized date in the attribute.This is like providing a 'dedicated translator' for search engines, ensuring that it can accurately understand the publishing or update time of the content, regardless of the human-readable format displayed on the page. - Optimize content timeliness judgment:For content that requires high timeliness, such as news, blogs, events, etc., search engines will judge the freshness of the content based on
datetimeproperties. If your content is frequently updated, make suredatetimeThe attribute reflects isUpdatedTimewhich will help search engines more accurately assess whether your content still has value. - Increase the opportunity to obtain rich text summaries (Rich Snippets):In some cases, providing structured date information (especially when combined with Schema Markup) can help your page display as rich text snippets in search results, such as search results with additional information like publication date, event date, etc., which can significantly increase click-through rates.
- Improve Accessibility:While not a direct SEO benefit, for users using screen readers,
<time datetime="...">labels can better convey time information, enhancing the overall user experience of the website.
stampToDateWithdatetimeThe perfect combination
Now, let's take a look at how to seamlessly integrate these two in the Anqi CMS template to achieve double optimization of date information:
Assuming we want to display the publication time on a document detail page while considering both user reading and search engine understanding, we can write the template code in this way:
{# 获取当前文档的发布时间戳 #}
{% archiveDetail archiveCreatedTime with name="CreatedTime" %}
<p>发布于
<time datetime="{{ stampToDate(archiveCreatedTime, "2006-01-02T15:04:05Z07:00") }}">
{{ stampToDate(archiveCreatedTime, "2006年01月02日") }}
</time>
</p>
{# 如果是更新时间,操作类似 #}
{% archiveDetail archiveUpdatedTime with name="UpdatedTime" %}
<p>最后更新于
<time datetime="{{ stampToDate(archiveUpdatedTime, "2006-01-02T15:04:05Z07:00") }}">
{{ stampToDate(archiveUpdatedTime, "2006年01月02日 15:04") }}
</time>
</p>
In this code snippet, we did several things:
- Pass
{% archiveDetail ... %}The tag fetched the timestamp of the document's creation (archiveCreatedTime). - In
<time>Inside the tag, we usedstampToDateFormat a user-friendly date, for example, "October 26, 2023". - The most crucial point is,
<time>Tagsdatetimewe used the attribute again.stampToDateBut this time is according to the ISO 8601 standard("2006-01-02T15:04:05Z07:00"corresponding toYYYY-MM-DDTHH:MM:SSZwhere,Z07:00The information of the time zone is used to format the date and time. This way, the search engine can accurately identify this standardized time.
Common Questions and Answers (FAQ)
Q1: What is a Unix timestamp? Why does Safe CMS use it?A1: A Unix timestamp is the number of seconds that have elapsed since January 1, 1970, at 00:00:00 UTC/GMT time, and is typically a 10-digit or 13-digit integer.The AnQi CMS uses Unix timestamps to store time because it is an internationally recognized, time zone-independent, easy-to-calculate, and easy-to-store standardized time representation.This unified format avoids confusion caused by different time zones and date formats, making it convenient for the system to handle internally and for cross-platform interaction.
Q2:datetimeAre there strict requirements for the date format of properties? Which one should be used?A2: Yes,datetimeThe date format of the attribute is strictly required, it needs to follow the ISO 8601 standard. The most common formats include:
- Only date:
YYYY-MM-DD(For example: