Security CMS Practical Guide:stampToDateWith HTMLdatetime: How to give wings to your website's SEO?
As an experienced website operations expert, I know that every detail may be the key to a website standing out in the increasingly fierce internet competition.For SEO, content quality is indeed the core, but optimization at the technical level should not be ignored either.Today, let's delve into a practical and SEO-boosting trick in AnQiCMS (AnQiCMS): how to cleverly utilizestampToDateApply the formatted date to the HTML'sdatetimeProperty.
Since its inception, AnQi CMS has integrated "SEO-friendly" into its design genes.From flexible pseudo-static rules, to comprehensive TDK (Title, Description, Keywords) management, to advanced SEO tools such as Sitemap generation and link push, all reflect the determination to help users achieve better visibility in search engines.On time information processing, AnQiCMS also provides strong support, such as its "Time Factor-Scheduled Publication Function", making content operation more flexible.And today we will talk about the art of formatting time information on the page, as well as how it communicates at a deeper level with search engines.
Identifying the value of time: Why should date information be treated specially?
On our website, dates and times are ubiquitous elements, 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 information;But for search engines, it is just text like "October 26, 2023", which humans can understand, but machines may not be able to accurately interpret its inherent meaning, especially in cross-language and cross-cultural environments.
This raises a core question: How can we ensure that the user's reading experience is not compromised while also allowing search engines to accurately and correctly understand the time information on the page? The answer lies in the introduction of HTML5.<time>elements anddatetimeProperty.
Of Security CMSstampToDate: magic stick of timestamp
The Anqi CMS usually stores time information for dynamic content in the form of Unix timestamps. For example, when we call the document details, archive.CreatedTimeandarchive.UpdatedTimeThe field returns a 10-digit timestamp. These original timestamps are difficult for users to understand as they are a sequence of numbers, so we need to format them.
At this point, the template engine of Anqi CMS comes into play, providing a very convenient timestamp formatting tag:stampToDate. This tag is like a 'magic wand' that can transform the cold timestamp into any date and time format we need. Its usage is very intuitive:{{stampToDate(时间戳, "格式")}}.
This "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 output year, month, day, hour, minute, second, and even the day of the week. For example,"2006-01-02"Can be formatted as "2023-10-26""2006年01月02日 15:04"It can be formatted as
HTMLdatetimeProperty: The exclusive translator of the search engine
NowstampToDateWe can easily display beautiful dates for users. But to further improve SEO, we need to introducedatetimeProperty. This property is specifically used for<time>Tag, its purpose is to provide a machine-readable date or time format, usually followingISO 8601 standardformat.
Then, put the formatted date intodatetimeWhat benefits does this attribute have for SEO?
- Enhance the search engine understanding:Search engines' crawlers and algorithms will read
datetimeThe standardized date in the attribute. This is like providing a 'personal translator' for search engines, ensuring that it can accurately understand the publication or update time of the content, regardless of the human-readable format displayed on the page. - Optimize the timeliness judgment of the content:For news, blogs, events, and other content that requires timeliness, search engines will judge the freshness of the content based on
datetimeattributes. If your content is frequently updated, make suredatetimeThe attribute reflectsUpdatedTimewhich will help search engines more accurately evaluate whether your content is still valuable. - increase the opportunity to get 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 dates, event dates, etc., which can significantly increase click-through rates.
- Improve accessibility:Although it is not a direct SEO benefit, for users who use screen readers,
<time datetime="...">tags 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 combine these two in Anqi CMS templates to achieve dual optimization of date information:
Assuming we want to display the publication time of 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:
- By
{% archiveDetail ... %}The tag obtained the document's creation timestamp (archiveCreatedTime) - In
<time>Inside the tag, we usedstampToDateFormat a user-friendly date, for example “October 26, 2023”. - The most critical thing is, in
<time>label'sdatetimethe property, we used againstampToDateThis time is according to the ISO 8601 standard("2006-01-02T15:04:05Z07:00"corresponding toYYYY-MM-DDTHH:MM:SSZof whichZ07:00Indicates time zone information) to format dates and times. This way, search engines can accurately identify this standardized time.
In this way, we not only provide visitors with clear and easy-to-understand date information, but also provide search engines with accurate, machine-readable data, thereby greatly optimizing the page's SEO performance without affecting the user experience.The strength and flexibility of AnQi CMS, precisely through these fine features, help our website go further in the digital world.
Frequently Asked Questions (FAQ)
Q1: What is a Unix timestamp? Why does Anqi CMS use it?A1: Unix timestamp is the number of seconds elapsed since 00:00:00 UTC/GMT on January 1, 1970, and is typically a 10-digit or 13-digit integer.The AnQi CMS uses Unix timestamps to store time because it is an internationally standardized, time zone-independent, easy-to-calculate and store time representation.This unified format avoids confusion caused by different time zones and date formats, which is convenient for internal processing and 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 and it needs to follow the ISO 8601 standard. The most common formats include:
- Only the date:
YYYY-MM-DD(For example:)