使用Blogger中的条件语句,我正在尝试将脚本添加到特定的URL。我从来没有能够让它工作,我一直把它推迟到现在。
在此site,它说要使用:<b:if cond='data:blog.url == "PUT_URL_HERE"'>
这就是我的尝试:
<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>
虽然,它不起作用。当我查看源代码时,该脚本未加载。我做错了什么?
答案 0 :(得分:9)
您可以使用以下条件匹配标签名称
<b:if cond='data:blog.searchLabel == "Label Name">
this will come up only on the label pages of 'Label Name'
</b:if>
当您创建匹配网址的条件时,请不要使用data:blog.url
,而是使用data:blog.canonicalUrl
,否则最终会在不同国家/地区呈现不同的代码。
<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>
参考:http://www.bloggerplugins.org/2012/02/country-specific-blogspot-urls.html
答案 1 :(得分:2)
复制粘贴此确切代码,它将起作用
<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>
当你在印度打开你的博客时,它会重定向到blogspot.in ......也许你包括.in(或其他一些国家代码)而不是.com
答案 2 :(得分:2)
data:blog.url
也将包含查询字符串,因此在您的情况下,数据标记不是很有用。
我不知道Blogger数据标记会返回没有查询字符串的URL。 您可以尝试使用javascript替换该博客条件语句。
这样的事情:
if (window.location.href.split('?')[0]=='http://xarpixels.blogspot.com/search/blog')
{
...
}
此外,我不确定您的搜索网址是否正确。在我的Blogger网站上,我喜欢这样:
http://mybloggersite.blogspot.com/search?q=