实时更新Disqus评论计数器

时间:2021-08-23 06:52:12

I am working on a Google Blog and Disqus comments counter updates with delay up to 10 minutes. So I try to make it counts in real time. I contacted with Disqus support and they told me this...

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

Please note that the comment count script is not expected to update in Realtime, and can experience delays of up to 10 minutes when configured properly.

请注意,评论计数脚本不会在实时更新,并且在正确配置时可能会遇到长达10分钟的延迟。

If you are looking for realtime comment counts, we do have some Advanced Options which you are free to implement on your site, though any additional questions regarding these methods should be directed towards our Developer Forum: - Use a hook to increment the displayed comment count every time a new comment comes in in real-time which would be possible to do since Disqus is already loaded in the background. To accomplish this, you could just provide a callback as described on this page:https://help.disqus.com/customer/portal/articles/466258-capturing-disqus-commenting-activity-via-callbacks and increment the count every time your callback gets called.

如果您正在寻找实时评论计数,我们确实有一些您可以在您的网站上*实施的高级选项,但是有关这些方法的任何其他问题应该针对我们的开发者论坛: - 使用钩子来增加显示的评论数量每次有新的评论实时进入,因为Disqus已经在后台加载了。要实现此目的,您可以按照此页面上的说明提供回调:https://help.disqus.com/customer/portal/articles/466258-capturing-disqus-commenting-activity-via-callbacks并每次递增计数你的回调被调用的时间。

If you still would like to poll, try using the comment count script as described on this page: https://help.disqus.com/customer/portal/articles/565624-tightening-your-disqus-integration. Once this is loaded, you can just call the function: DISQUSWIDGETS.getCount({reload: true}); when you want to poll and it will update the comment count for you. This endpoint is heavily optimized on our end for this use case.

如果您仍想轮询,请尝试使用此页面中所述的评论计数脚本:https://help.disqus.com/customer/portal/articles/565624-tightening-your-disqus-integration。加载后,您只需调用函数:DISQUSWIDGETS.getCount({reload:true});当你想要进行民意调查时,它会为你更新评论数量。对于此用例,此端点在我们的端部进行了大量优化。

My problem is... Where exactly should I place this DISQUSWIDGETS.getCount({reload: true});? Cause I have make some tries but, nothing!!!

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

Here is an example of my code...

这是我的代码的一个例子......

Disqus comments count link:

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 comments widget:

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>

Load Disqus comments on click:

在点击上加载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 个解决方案

#1


2  

Add the following code to your blog -

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

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

This will update the comment count every time a new comment is added via the page.

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

#1


2  

Add the following code to your blog -

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

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

This will update the comment count every time a new comment is added via the page.

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