开发者

Tumblr: How to hide Disqus comments on Pages?

开发者 https://www.devze.com 2023-03-10 04:36 出处:网络
As far as I am aware in Tumblr there is no {block:Pages} block, so anything we add to normal posts is added to pages as well, things like sharing and worst of all, comment systems.

As far as I am aware in Tumblr there is no {block:Pages} block, so anything we add to normal posts is added to pages as well, things like sharing and worst of all, comment systems.

Does anyone know of a hack, or any way to remove/hide elements from pages? It's difficult because pages are using the {block:Permalink} {block:Text} blocks, so I'm pretty stumped.

I recently just discovered how to modify CSS with post tags using just HTML over here: Tumblr: How to control CSS with post tagging (UPDATE: Working Method without JQuery!)

I thought maybe we can use this, the idea would be something like this:

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

The way it works is by default we hide any element we don't want to be shown on pages (example: Disqus), adding the class .pagefix between {block:HasTags} in the div wrapper we can tell it to show elements on posts with tags, that way elements will only be shown on posts and not pages, because pages don't have tags.

Two problems with this, 1) all posts MUST be tagged in order to show any hidden items and 2) the Disqus comment script would have to be inserted into every post type, rather than just once before the {/block:Posts} end block.

I may be just placing Disqus in the wrong place, or some other error, let me know what you think, I can't find anything at all about this on the net anyw开发者_开发知识库here. It's so dumb not to have a unique page block...


Simply wrap your Disqus code in the date block.

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

Since only posts have dates, the Disqus code will never get rendered on a page. This also solves the problem above where having only one post breaks the method.


The trick is to wrap your Disqus code in {block:PermalinkPagination} tags as follows:

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

Your question is a partial duplication of this one on webapps.stackexhange.com, a full explanation can be found here.


There is also a problem with disqus code whereby if you want to have the comment count show on the front page but not a comment box (but have the comment box and comments as well as the comment count show on the Permalink page) you must do the following:

Append #disqus_thread to the direct page link e.g. <a href="{Permalink}#disqus_thread"></a>

Do NOT wrap the disqus code in {block:PermalinkPagination}{/block:PermalinkPagination} as this will hide comments from the front page. Remove that block if it exists, and wrap the top part of the disqus script only in {block:Permalinkpage}{/block:Permalinkpage} - exact disqus code for Tumblr reproduced below;

            {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>
0

精彩评论

暂无评论...
验证码 换一张
取 消