【问题标题】:Disqus not displaying comment countDisqus不显示评论数
【发布时间】:2015-10-11 08:54:04
【问题描述】:

总结: 我正在设置 disqus 以在我们的 MVC .net 站点内的页面上显示评论计数。我之前在 Tumblr 页面上“修复”过这个功能,所以我认为我有必要的技能在这个网站上相当容易地做到这一点,但我失败了。我还查看了 Ryan (https://stackoverflow.com/users/1370956/ryan-v) 的所有适用答案,但没有找到解决方案。

我正在遵循 disqus.com 的指示:

https://help.disqus.com/customer/portal/articles/565624

但我没有成功。我的理解是,我需要做的就是:

  1. 添加替换了 disqus_shortname 的脚本
  2. 在文章网址末尾插入带有“#disqus_thread”的href标签

一旦完成,我认为脚本应该插入评论计数并将其显示在页面上——但这对我不起作用。

在 tumblr 你应该插入一个元标记

<meta name='text:Disqus Shortname' content='' />

但我不认为这适用于我的设置(尽管这并没有阻止我尝试一下)。

我只能假设我遗漏了一些明显的东西。我想知道 localhost 环境是否会中断我的测试,因为我正在使用指向显示 disqus cmets 的 localhost 页面的链接。我还使用实时 disqus 评论页面进行了测试,但结果相同。

详情: 目前我已经测试了一些错误的东西,但我认为以下是错误最少的:

脚本:

<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'My-Shortname'; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function () {
        var s = document.createElement('script'); s.async = true;
        s.type = 'text/javascript';
        s.src = '//' + disqus_shortname + '.disqus.com/count.js';
        (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
    }());
</script>

HTML:

<a href="http://localhost-link/#disqus_thread"></a>

【问题讨论】:

    标签: javascript html comments disqus


    【解决方案1】:

    所以,这对于那些永远不会真正看这个问题的人来说可能是非常有意义的,事实证明,单独使用“#”对我们不起作用,而是必须结合使用带有“&” - 一个例子:

    &lt;a href="http://localhost-link&amp;#disqus_thread" data-disqus-identifier="12345"&gt;&lt;/a&gt;

    最后也使用了标识符属性,您可以在我原来的问题中链接的同一篇 disqus 文章中阅读有关该属性的信息。

    【讨论】:

    • 我发现hrefdata-disqus-url 对我不起作用。我必须使用 data-disqus-identifier 和我的页面 ID。
    【解决方案2】:

    添加 '&' 似乎确实可以解决问题。

    如果您使用标签助手,您可以将 & 添加到 asp-fragment。例如。

    <a asp-area="" asp-controller="Blog" asp-action="Read" asp-route-id="@post.OriginalPost.ID" asp-fragment="&disqus_thread" data-disqus-identifier="@post.OriginalPost.ID"></a>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-12
      • 2013-04-21
      • 2018-03-20
      • 2014-02-13
      • 2013-08-07
      • 2011-08-16
      相关资源
      最近更新 更多