简体   繁体   中英

Change color by Blogger Tag

is there any way to change some blogger areas by tag?

Example, I'm on a page that has the tag cars, only this page would have as a few sections:

.body .header

have a different color from other pages?

I got this script that changes the background color of the site every 12 hours, but it's still not what I'm looking for, what I would like was to change parts of the blog as the tag changed

<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>

More information:

I know it is possible to use this code to make the changes happen, but the changes only happen on the label page, as the changes happen on all pages that have the car tag.

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

The snippet in the end of your question will work perfectly in labels page. In article page you need a similar code to check if post has a specific tag, so you need to add the next code within main 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM