Xarcell
Xarcell

Reputation: 2011

Blogger Search Label Conditional Statements

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 == &quot;http://www.website.com/search/?q=label:Graphics|label:Identity|label:Brand&quot;'>
    <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 == &quot;Graphics|Identity|Brand&quot;'>
    <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

Answers (3)

Taufik Nurrohman
Taufik Nurrohman

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

You can try do it separately for each tag:

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

then

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

and finally...

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

make sure you use the exact label with uppercase letters etc!

Upvotes: 2

gxg
gxg

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 == &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.

Upvotes: 1

Related Questions