Update 11/3/2014:
We now have a method for using comment counts on any element you want. The regular count.js腳本將現在的工作,如果你:
- 使用
disqus-comment-count
類
- 使用
data-disqus-url
或data-disqus-identifier
屬性
所以現在任這些元素將工作:
<span class="disqus-comment-count" data-disqus-url="http://example.com/path-to-thread/"> <!-- Count will be inserted here --> </span>
和
<span class="disqus-comment-count" data-disqus-identifier="your_disqus_identifier"> <!-- Count will be inserted here --> </span>
老答案(不要再這樣做了)
的count.js腳本是相當固定的,當涉及到的各類標籤的尋找(它必須是一個a
標籤),所以你需要使用API來完成這個。
這個API調用返回線程數據數組(你正在尋找的「帖子」整數)爲您指定的任何數量的線程:http://disqus.com/api/docs/threads/set/
由於API限制你最好運行該服務器並緩存計數以供客戶端使用。但是,除非你有一個非常繁忙的網站,否則在客戶端做這件事通常很好。如果您的應用程序需要超過1000個請求/小時,則可以發送郵件至[email protected]。
編輯
這裏是你如何能做到這一點使用jQuery一個簡單的例子。這是假設你有幾個空的div的看起來像這樣:
<div class="my-class" data-disqus-url="http://example.com/some-url-that-matches-disqus_url/"></div>
文件的javascript:
$(document).ready(function() {
var disqusPublicKey = "YOUR_PUBLIC_KEY";
var disqusShortname = "YOUR_SHORTNAME";
var urlArray = [];
$('.my-class').each(function() {
var url = $(this).attr('data-disqus-url');
urlArray.push('link:' + url);
});
$('#some-button').click(function() {
$.ajax({
type: 'GET',
url: "https://disqus.com/api/3.0/threads/set.jsonp",
data: { api_key: disqusPublicKey, forum : disqusShortname, thread : urlArray }, // URL method
cache: false,
dataType: 'jsonp',
success: function (result) {
for (var i in result.response) {
var countText = " comments";
var count = result.response[i].posts;
if (count == 1)
countText = " comment";
$('div[data-disqus-url="' + result.response[i].link + '"]').html('<h4>' + count + countText + '</h4>');
}
}
});
});
乾杯瑞安。我覺得很奇怪,爲什麼它必須是A標籤 - 對我來說好像是一個很大的疏漏。我們的網站今天收到大約25-30k的訪問者,所以是非常高的流量 - 這可能會使其每小時1000+個請求類別?它昨天有73k頁面瀏覽量。 – pixelkicks 2013-05-03 07:08:34
發郵件給[email protected] - 我們可以達到極限,我們只是想確保我們已經聯繫,以確保一切順利:-) – 2013-05-05 04:47:49
嗨,瑞安,我們剛剛嘗試過電子郵件,但我們得到了反彈說我們沒有權限或Google組不存在? – pixelkicks 2013-05-10 13:42:25