Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blogger URL Condition Statements

Tags:

xml

blogger

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?

like image 608
Xarcell Avatar asked May 16 '13 16:05

Xarcell


3 Answers

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

like image 54
coderplus Avatar answered Sep 28 '22 14:09

coderplus


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

like image 22
Rahul Shah Avatar answered Sep 28 '22 15:09

Rahul Shah


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=
like image 36
user850010 Avatar answered Sep 28 '22 16:09

user850010