4

我正在尝试基于 URL 在博客中添加 CSS。URL 是对多个标签的搜索,使用: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 必须在文档中,而不是外部来源。

4

3 回答 3

4

您现在可以使用:

<b:if cond='data:blog.searchLabel in ["Graphics", "Identity", "Brand"]'>
  <style type="text/css"> ... </style>
</b:if>
于 2018-09-05T16:39:00.320 回答
2

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

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

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

于 2016-11-17T11:26:48.973 回答
1

I'm not sure if Blogger supports an OR operator in the XML template, so you should probably try to nest the conditions, something like:

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]

Not very efficient, but unfortunately I don't see another solution...

Otherwise you could simply add the required style in the regular template, give it a class, and then use Java Script to dynamically add the class depending on the selected label.

于 2013-09-02T08:30:11.157 回答