问题
I'm using blogger, and I want to use different <title>
tags depending on the post labels. For example, if a post has the label: "SOMELABEL1", it will show <title>Title1 - Wbsitename</title>
, and if the post has the label: "SOMELABEL2", it will show <title>2222 - Webitename</title>
.
I have tried to use the following code (which is working on the middle of the page - in the body), but not in the head start:
<b:if cond='data:post.labels any (l => l.name in "LABEL1")'>
<title>1111 - Webitename</title>.
<b:else/>
<title>2222 - Webitename</title>.
</b:if>
Please help.
回答1:
You can not check data:post.labels
outside the Blog widget but the good news is that you can use your code inside Blog widget to change the page title via JavaScript.
<b:if cond='data:post.labels any (label => label.name == "LABEL1")'>
<script type="text/javascript">
document.title="1111 - Webitename";
</script>
<b:else/>
<script type="text/javascript">
document.title="2222 - Webitename";
</script>
</b:if>
But changing the page title via JavaScript won't help SEO because some web crawlers do not support JavaScript. (Google's does)
来源:https://stackoverflow.com/questions/42178327/how-to-check-if-a-post-has-a-specific-label-using-conditional-tags