跳转到内容
无痕工具库 无痕工具库

Hostinger AI 建站工具手动模式修改博客文章日期格式教程

使用自定义代码,为你的 Hostinger AI Builder 手动模式网站上的所有博客文章更改日期格式。

复制代码

<script>
function formatDate(date) {
let d = new Date(date.innerText),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day + " "].join('/');
}
setInterval(() => {
if (document.contains(document.querySelector('.block-blog-list')) && document.querySelector('.block-blog-list-item:last-of-type .blog-list-item-meta__subtitle span:first-of-type').innerHTML.at(-1) !== ' ') {
let randomPosts = document.querySelectorAll('.block-blog-list-item');
randomPosts.forEach(post => {
post.querySelector('.blog-list-item-meta__subtitle span:first-of-type').innerText = formatDate(post.querySelector('.blog-list-item-meta__subtitle span:first-of-type'));
})
}
if (document.contains(document.querySelector('.block-blog-header')) && document.querySelector('.blog-list-item-meta__subtitle span:first-of-type').innerHTML.at(-1) !== ' ') {
document.querySelector('.blog-list-item-meta__subtitle span:first-of-type').innerText = formatDate(document.querySelector('.blog-list-item-meta__subtitle span:first-of-type'));
}
}, 500);
</script>

自定义代码

根据你偏好的日期格式,在此处更改值的排列顺序:

return [year, month, day + " "].join('/');

上面的示例会以以下格式返回日期:yyyy/mm/dd.

粘贴代码

在 AI Builder 中,进入你网站的更多选项(…)→ 集成,并将代码粘贴到**自定义代码字段中。然后,保存更改并更新你的网站**。

此更改将在预览模式和线上可见,但在编辑器中不可见。

如需了解博客文章、页眉和区块的其他配置选项,请参阅 如何管理博客设置。