Blogger URL Condition Statements
Asked Answered
M

3

5

Using the condition statements in Blogger, I'm trying to add a script to a specific URL. I have never been able to get this to work, and I have been putting it off until now.

At this site, it says to use: <b:if cond='data:blog.url == "PUT_URL_HERE"'>

So that's what I tried:

<b:if cond='data:blog.url == "http://xarpixels.blogspot.com/search/blog"'>
  <script>
    $( document ).ready(function() {
      var $content = $('#main');
        $content.imagesLoaded( function(){
        $content.masonry({
          itemSelector : '.post';
        });
      });
    });
  </script>
</b:if>

Although, it isn't working. When I view the source, that script is not loading. What am I doing wrong?

Monsoon answered 16/5, 2013 at 16:21 Comment(6)
where are u putting this code?wont work in widgets...u will have to put this in template..Bliss
Obviously.... Of course I'm putting it in the template.Monsoon
Perhaps it wont work on the link you specified,try a link of a post/static page/home page.Bliss
no link works, regardless of what I put there.Monsoon
u mean to say code does not come up in the source code right?Bliss
I'm having the same problem. Just trying to add a comment within and the condition is not working. I've tried data:blog.pageType (works fine), and I've also tried this: cond='data:blog.url == data:blog.homepageUrl' - also works as expected. any other URL supplied in quotes and the condition is not being triggeredBranchia
M
11

You can match the label name using the below condition

<b:if cond='data:blog.searchLabel == "Label Name">
  this will come up only on the label pages of 'Label Name'
</b:if>

When you make conditions to match URLs, never use data:blog.url but use data:blog.canonicalUrl instead or else you will end up having different code being rendered across different countries.

<b:if cond='data:blog.canonicalUrl == "http://blog.blogspot.com/2013/05/post.html"'> 
  Text or code that will be displayed only on specific url
</b:if>

Reference : http://www.bloggerplugins.org/2012/02/country-specific-blogspot-urls.html

Maulstick answered 18/5, 2013 at 9:26 Comment(1)
I decided to go with the label method. Works great and serves my needs. Thanks.Monsoon
B
2

Copy paste this exact code and it will work

<b:if cond='data:blog.url == "http://xarpixels.blogspot.com/2013/04/test-post.html"'> 
Text or code that will be displayed only on specific url
</b:if>

When you open ur blog in India,it redirects to blogspot.in......perhaps u were including .in (or some other country code)instead of .com

Bliss answered 17/5, 2013 at 3:24 Comment(2)
the script you posted works, however it doesn't work on the URL I need it too. So I reckon that's a step closer. is there a condition statement for just the search? Not search labels, but just plain ole search?Monsoon
to the best of my knowledge no........ Try posting this question in the official blogger forumBliss
M
2

That data:blog.url will contain query string too, so that Data Tag is not that useful in your case.

I'm not aware of Blogger Data Tag that would return URL without query strings. You could try to replace that blogger conditional statement with a javascript.

Something like this:

  if (window.location.href.split('?')[0]=='http://xarpixels.blogspot.com/search/blog')
  {
      ...
  }

Also I'm not sure your search URL is correct. On my Blogger site I have it like this:

http://mybloggersite.blogspot.com/search?q=
Mediocre answered 17/5, 2013 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.