问题描述
我正在使用博客,并且我想根据帖子标签使用不同的<title>
标签.例如,如果帖子的标签为:"SOMELABEL1",则显示为<title>Title1 - Wbsitename</title>
;如果帖子的标签为:"SOMELABEL2",则显示为<title>2222 - Webitename</title>
.
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>
请帮助.
推荐答案
您无法在Blog小部件外部检查data:post.labels
,但好消息是您可以使用Blog小部件中的代码通过JavaScript更改页面标题.
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>
但是,通过JavaScript更改页面标题不会帮助SEO,因为某些Web爬网程序不支持JavaScript. (Google的)
But changing the page title via JavaScript won't help SEO because some web crawlers do not support JavaScript. (Google's does)
这篇关于如何检查帖子是否具有特定标签(使用条件标签)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!