gpt4 book ai didi

javascript - 通过 Blogger 标签更改颜色

转载 作者:行者123 更新时间:2023-11-27 22:53:02 25 4
gpt4 key购买 nike

有什么办法可以通过标签改变一些博客区吗?

例如,我在一个有标签 cars 的页面上,只有这个页面会有几个部分:

.正文.header

与其他页面有不同的颜色?

我得到了这个脚本,它每 12 小时更改一次网站的背景颜色,但它仍然不是我要找的,我想要的是随着标签的更改更改博客的某些部分

<script type='text/javascript'>//<![CDATA[ 
var currentTime = new Date().getHours();
if (6 <= currentTime && currentTime < 12) {
document.body.style.backgroundColor = "#1abc9c";
} else if (12 <= currentTime && currentTime < 18) {
document.body.style.backgroundColor = "#318fcb";
} else {
document.body.style.backgroundColor = "#560256";
}
//]]></script>

更多信息:

我知道可以使用此代码进行更改,但更改仅发生在标签页面上,因为更改发生在所有具有汽车标签的页面上。

<b:if cond='data:blog.searchLabel == "car"'>
<style type='text/css'>
body { background: #e2ad44 !important }
</style>
</b:if>

最佳答案

问题末尾的代码片段将在标签页面中完美运行。在文章页面中,您需要类似的代码来检查帖子是否具有特定标签,因此您需要在 ma​​in blog posts loop 中添加下一个代码:

<!-- check if page type is article page & check if article has a "car" tag -->
<b:if cond='data:view.isPost and data:post.labels any (l => l.name == "car")'>
<style>
body { background: #e2ad44 }
</style>
</b:if>

关于javascript - 通过 Blogger 标签更改颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59366598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com