Reputation: 2011
I'm trying to add CSS in blogger based on URL. The URL is a search of multiple labels using: http://www.website.com/search/?q=label:Graphics|label:Identity|label:Brand . The search for multiple labels works, but I cannot figure out how to make a conditional statement for it.
I tried:
<b:if cond='data:blog.canonicalUrl == "http://www.website.com/search/?q=label:Graphics|label:Identity|label:Brand"'>
<style type="text/css">
...
</style>
</b:if>
That won't work because of queries in the URL. So then I tried:
<b:if cond='data:blog.searchLabel == "Graphics|Identity|Brand"'>
<style type="text/css">
...
</style>
</b:if>
That doesn't work, nor does it seem proper. I'd rather have it done in XML, but if I cannot javascript will do. I even tried:
if(window.location('http://www.website.com/search/?q=label:Graphics|label:Identity|label:Brand') === 0)
document.write("<style type='text/css'> ... </style>
);
BTW, the CSS must be in the doc, not an external source.
Upvotes: 4
Views: 2269
Reputation: 3409
You can now use:
<b:if cond='data:blog.searchLabel in ["Graphics", "Identity", "Brand"]'>
<style type="text/css"> ... </style>
</b:if>
Upvotes: 4
Reputation: 71
You can try do it separately for each tag:
<b:if cond='data:blog.searchLabel == "Graphics"'>
<style type="text/css">
...
</style>
</b:if>
then
<b:if cond='data:blog.searchLabel == "Identity"'>
<style type="text/css">
...
</style>
</b:if>
and finally...
<b:if cond='data:blog.searchLabel == "Brand"'>
<style type="text/css">
...
</style>
</b:if>
make sure you use the exact label with uppercase letters etc!
Upvotes: 2
Reputation: 11
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 == "Graphics"' [code]
else if cond='data:blog.searchLabel == "Identity"' [same code]
else if cond='data:blog.searchLabel == "Brand"' [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.
Upvotes: 1