我的条件标签在博主帖子中不起作用
让我们举个例子,我的网站网址是这样的Example.com/p/post.html
这里我要显示英文内容
但是当URL切换到这个Example.com/p/post.html?hl=hi
我想在帖子中显示其他内容
我设置了条件,以便当 URL 在上面时显示 content1
如果 URL 是第二个显示 content2
我在帖子中使用的条件是这样的
<b:if cond='data:blog.url == data:blog.canonicalHomepageUrl + "2016/07/blogger-conditional-tags-for-page-types.html?hl=hi"'>
<div>
अंकित
</div>
<b:elseif cond='data:blog.url == data:blog.canonicalHomepageUrl + "2016/07/blogger-conditional-tags-for-page-types.html"'/>
<div>ankit true
</div>
</b:if>
但这不起作用,它同时显示 अंकित
和 ankit
在两个 URL 上。一切尽在博主。
最佳答案
我有一个类似的问题,并用一些 jQuery 和 Css 解决了它。
将您的帖子写在 HTML 上并首先将这两个内容包装起来,例如
<div id="content1">
Content show with url without ?hl=hi
</div>
<div id="content2">
Content to hide/show with chosen url
</div>
然后添加 css - 请记住包含包装 CSS 样式的标签:#content2 {display:none;}
最后是 jQuery 脚本位 - 再次记住包含包装代码的脚本标签: $(document).ready(function() {
url = document.location.href;
if (url.indexOf("?hl=hi") != -1) {
$("#content2").show();
$("#content1").hide();
}
});
您可以检查下面编辑的代码段以使用您的网址:$(document).ready(function() {
//url = document.location.href;
url = "http://example.com/p/post.html?hl=hi";
if (url.indexOf("?hl=hi") != -1) {
$("#content2").show();
$("#content1").hide();
}
});
#content2 {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div id="content1">
Content visible with url NOT containing <b style='color:#f00'>?hl=hi</b> at the end
</div>
<div id="content2">
Content to hide/show with chosen url with <b style='color:#f00'>?hl=hi</b> at the end
</div>
关于javascript - 为什么我的条件标签在 Blogger 帖子中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70054812/