【问题标题】:Why My Conditonal Tags are not working inside the Blogger post为什么我的条件标签在 Blogger 帖子中不起作用
【发布时间】:2021-12-31 09:45:49
【问题描述】:

我的条件标签在博主帖子中不起作用 让我们举个例子,我的网站网址是这样的

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>

但这不起作用,它在两个 URL 上都显示 अंकितankit

一切尽在博客中。

【问题讨论】:

  • 你现在可以检查我是否更新了它

标签: javascript post conditional-statements seo blogger


【解决方案1】:

我遇到了类似的问题,用一点 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();
       }
    });

您可以检查下面编辑的 sn-p 以使用您的网址:

$(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/css 解决方案,因为我的理解是条件标签在博客文章中不起作用。我提出的解决方案并解决了我的问题,可以放在博客文章中。根据我的经验,条件标签必须放置在模板 HTML 本身上,我不知道如何让它们按照您的要求工作......对不起,我无法提供更多帮助。
猜你喜欢
  • 1970-01-01
  • 2010-12-12
  • 1970-01-01
  • 2018-04-08
  • 1970-01-01
  • 2018-07-21
  • 1970-01-01
  • 2018-05-04
相关资源
最近更新 更多