实时更新Disqus评论计数器

时间:2016-07-26 10:05:50

标签: javascript jquery ajax blogger disqus

我正在开发Google博客和Disqus评论计数器更新,最多延迟10分钟。所以我试着让它实时计算。我联系了Disqus支持,他们告诉我这个......

  

请注意,评论计数脚本不会更新   实时,并且可以在最长10分钟时遇到延迟   配置得当。

     

如果您正在寻找实时评论计数,我们确实有一些   但是,您可以在您的网站上自由实施高级选项   有关这些方法的任何其他问题都应该针对   对我们的开发者论坛:    - 每当新评论实时进入时,使用钩子增加显示的评论计数,这是可能的   Disqus已经在后台加载了。要做到这一点,你   可以提供回调,如上所述   页:https://help.disqus.com/customer/portal/articles/466258-capturing-disqus-commenting-activity-via-callbacks   并在每次调用回调时递增计数。

     

如果您仍想进行投票,请尝试使用评论计数脚本   本页描述:   https://help.disqus.com/customer/portal/articles/565624-tightening-your-disqus-integration。   加载后,您只需调用该函数:   DISQUSWIDGETS.getCount({reload:true});当你想要民意调查时   将为您更新评论计数。这个终点很重要   我们最终针对这个用例进行了优化。

我的问题是......我应该在哪里放置DISQUSWIDGETS.getCount({reload: true});?因为我做了一些尝试,但没有!!!!

以下是我的代码示例...

Disqus评论计数链接:

<b:if cond='data:post.allowComments'>
    <a class='disqus-comment-count' expr:href='data:post.url + &quot;#disqus_thread&quot;' onclick='return false;'>Counting...</a>
</b:if>

Disqus评论小部件:

<b:widget id='HTML6' locked='false' title='Disqus Comments' type='HTML' visible='true'>
  <b:includable id='main'>
    <div id='comments' name='comments'>
      <div id="disqus_thread" />
    </div>
  </b:includable>
</b:widget>

Disqus count.js:

<script id="dsq-count-scr" src="//my-shortname.disqus.com/count.js" async='async'></script>

在点击时加载Disqus评论:

<script>
  $(document).ready(function() {
    $('#comments').on('click', function() {
      var disqus_shortname = 'my-shortname';
      $.ajax({
        type: "GET",
        url: "http://" + disqus_shortname + ".disqus.com/embed.js",
        dataType: "script",
        cache: true
      });
    });
  });
</script>

1 个答案:

答案 0 :(得分:2)

将以下代码添加到您的博客中 -

<script>
  var disqus_config = function () {
    this.callbacks.onNewComment = [function() { DISQUSWIDGETS.getCount({reset: true}); }];
  };
</script>

每次通过页面添加新评论时,这将更新评论计数。