Blogger搜索标签条件语句

时间:2013-08-30 11:03:32

标签: javascript xml blogger

我正在尝试根据网址在博客中添加CSS。该网址是使用以下内容搜索多个标签:http://www.website.com/search/?q=label:Graphics|label:Identity|label:Brand。搜索多个标签有效,但我无法弄清楚如何为它制作条件语句。

我试过了:

<b:if cond='data:blog.canonicalUrl == &quot;http://www.website.com/search/?q=label:Graphics|label:Identity|label:Brand&quot;'>
    <style type="text/css">
        ...
    </style>
</b:if>

由于URL中的查询,这不起作用。所以我试过了:

<b:if cond='data:blog.searchLabel == &quot;Graphics|Identity|Brand&quot;'>
    <style type="text/css">
        ...
    </style>
</b:if>

这不起作用,看起来也不合适。我宁愿用XML完成它,但是如果我不能用javascript做的话。我甚至尝试过:

if(window.location('http://www.website.com/search/?q=label:Graphics|label:Identity|label:Brand') === 0)
    document.write("<style type='text/css'> ... </style>
);
顺便说一句,CSS必须在doc中,而不是外部源。

3 个答案:

答案 0 :(得分:1)

我不确定Blogger是否支持XML模板中的OR运算符,因此您应该尝试嵌套条件,例如:

if cond='data:blog.searchLabel == &quot;Graphics&quot;' [code]
else if cond='data:blog.searchLabel == &quot;Identity&quot;' [same code]
else if cond='data:blog.searchLabel == &quot;Brand&quot;' [same code again]
else [the other option]

效率不高,但不幸的是我没有看到另一种解决方案......

否则,您只需在常规模板中添加所需的样式,为其指定一个类,然后使用Java Script根据所选标签动态添加类。

答案 1 :(得分:1)

您可以尝试为每个标记单独执行此操作:

<b:if cond='data:blog.searchLabel == &quot;Graphics&quot;'> <style type="text/css"> ... </style> </b:if>

然后

<b:if cond='data:blog.searchLabel == &quot;Identity&quot;'>
    <style type="text/css">
        ...
    </style>
</b:if>

最后......

<b:if cond='data:blog.searchLabel == &quot;Brand&quot;'>
    <style type="text/css">
        ...
    </style>
</b:if>

确保使用带有大写字母等的确切标签!

答案 2 :(得分:0)

您现在可以使用:

<b:if cond='data:blog.searchLabel in ["Graphics", "Identity", "Brand"]'>
  <style type="text/css"> ... </style>
</b:if>
相关问题