【问题标题】:Tumblr: How to hide Disqus comments on Pages?Tumblr:如何隐藏页面上的 Disqus 评论?
【发布时间】:2011-06-04 16:33:29
【问题描述】:

据我所知,在 Tumblr 中没有 {block:Pages} 块,因此我们添加到普通帖子中的任何内容也会添加到页面中,例如分享和最糟糕的是评论系统。

有谁知道黑客或任何从页面中删除/隐藏元素的方法?这很困难,因为页面正在使用 {block:Permalink} {block:Text} 块,所以我很难过。

我最近刚刚在这里发现了如何使用 HTML 来修改带有 post 标签的 CSS:Tumblr: How to control CSS with post tagging (UPDATE: Working Method without JQuery!)

我想也许我们可以使用这个,想法是这样的:

{block:Text}
  <div class="post {block:HasTags}pagefix {block:Tags}{Tag}{/...}">
  ...
{/block:Text}

它的工作方式是默认隐藏任何我们不想在页面上显示的元素(例如:Disqus),在 div 包装器中添加{block:HasTags} 之间的类.pagefix,我们可以告诉它显示带有标签的帖子上的元素,这样元素只会显示在帖子而不是页面上,因为页面没有标签。

这有两个问题,1)必须标记所有帖子才能显示任何隐藏的项目,2)必须将 Disqus 评论脚本插入到每个帖子中帖子类型,而不是只在 {/block:Posts} 结束块之前出现一次。

我可能只是将 Disqus 放在了错误的位置,或者其他错误,请告诉我您的想法,我在网上任何地方都找不到任何关于此的信息。没有独特的页面块真是太愚蠢了......

【问题讨论】:

    标签: css tumblr


    【解决方案1】:

    只需将您的 Disqus 代码包装在日期块中即可。

    {block:Date}
        <!-- Disqus code -->
    {/block:Date}
    

    由于只有 posts 有日期,因此 Disqus 代码永远不会在页面上呈现。这也解决了上面只有一个帖子破坏方法的问题。

    【讨论】:

      【解决方案2】:

      诀窍是将您的 Disqus 代码包装在 {block:PermalinkPagination} 标签中,如下所示:

      {block:PermalinkPagination}
         ...disqus code...
      {/block:PermalinkPagination}
      

      您的问题是 webapps.stackexhange.com 上this one 的部分重复,完整的解释可以在here 找到。

      【讨论】:

      • 看起来有一个新标签:{block:PermalinkPage} tumblr.com/docs/en/custom_themes
      • 这个技巧很好用,但是如果你只有一个帖子,技巧就坏了
      • 如下@graygilmore 所述,正确的方法是使用{block:Date}。上述方法具有误导性,容易失败。
      【解决方案3】:

      disqus 代码还有一个问题,即如果您想在首页显示评论计数而不是评论框(但在永久链接页面上显示评论框和 cmets 以及评论计数)您必须执行以下操作:

      将#disqus_thread 附加到直接页面链接,例如<a href="{Permalink}#disqus_thread"></a>

      不要将 disqus 代码包装在 {block:PermalinkPagination}{/block:PermalinkPagination} 中,因为这会将 cmets 从首页隐藏。如果该块存在,则删除该块,并将 disqus 脚本的顶部 包装在 {block:Permalinkpage}{/block:Permalinkpage} 中 - 下面复制了 Tumblr 的确切 disqus 代码;

                  {block:IfDisqusShortname}                    
                      {block:Permalinkpage}
                      <script type="text/javascript">var disqus_url = "{Permalink}"; var disqus_title ="{block:PostTitle}{PostTitle}{/block:PostTitle}";</script>
                      <div id="disqus_thread"></div>
                      <script type="text/javascript">
                      (function() {
                      var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
                      dsq.src = 'http://{text:Disqus Shortname}.disqus.com/embed.js';
                      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
                      })();
                      </script>
                      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript={text:Disqus Shortname}">comments powered by Disqus.</a></noscript>
                      {/block:Permalinkpage}
      
      
                      <!--<a href="http://disqus.com" class="dsq-brlink">{Title}'s comments powered by <span class="logo-disqus">Disqus</span></a>-->
                      <script type="text/javascript">
                      var disqus_shortname = '{text:Disqus Shortname}';
                      (function () {
                      var s = document.createElement('script'); s.async = true;
                      s.src = 'http://{text:Disqus Shortname}.disqus.com/count.js';
                      (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
                      }());
                      </script>
              {/block:IfDisqusShortname}
              </div>
      

      【讨论】:

        猜你喜欢
        • 2015-04-13
        • 1970-01-01
        • 2011-10-20
        • 2013-08-28
        • 1970-01-01
        • 2012-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多