簡體   English   中英

多個頁面的Disqus評論數

[英]Disqus comment count for multiple pages

以下代碼用於獲取多個頁面的Disqus評論數。

var DISQUSWIDGETS;

if (typeof DISQUSWIDGETS != 'undefined') {
    DISQUSWIDGETS.displayCount({
        "showReactions":true,
        "text":{
            "and":"and",
            "reactions":{
                "zero":"0 Reactions",
                "multiple":"{num} Reactions",
                "one":"1 Reaction"},
            "comments":{
                "zero":"0 Comments",
                "multiple":"{num} Comments",
                "one":"1 Comment"
            }
        },
        "counts":[
            {"reactions":0,"uid":1,"comments":2},
            {"reactions":0,"uid":2,"comments":5},
            {"reactions":0,"uid":3,"comments":9}
        ]
    });
}

我想從這里獲取評論示例的數量:

{"reactions":0,"uid":1,"comments":2}評論數應為2。

是否有任何僅能獲得注釋的javascript代碼?

如果您可以這樣重寫:

var DISQUSWIDGETS;

if (typeof DISQUSWIDGETS != 'undefined') {
    var disqus_options = {
        "showReactions":true,
        "text":{
            "and":"and",
            "reactions":{
                "zero":"0 Reactions",
                "multiple":"{num} Reactions",
                "one":"1 Reaction"},
            "comments":{
                "zero":"0 Comments",
                "multiple":"{num} Comments",
                "one":"1 Comment"
            }
        },
        "counts":[
            {"reactions":0,"uid":1,"comments":2},
            {"reactions":0,"uid":2,"comments":5},
            {"reactions":0,"uid":3,"comments":9}
        ]
    };
    DISQUSWIDGETS.displayCount(disqus_options);
}

然后,您將可以像這樣訪問計數:

disqus_options.counts[0].comments

在這種情況下,其值為2


編輯

要按id過濾,在這種情況下, id == 3

var counts_with_id = $.grep(disqus_options.counts, function(count) {
    return (count.uid == 3);
});
if (counts_with_id.length) // the id exists
    counts_with_id[0].comments // has value 9
else
    the id does not exist in the disqus_options.

編輯

您可以“破解” displayCount方法:

// Load the disqus plugin which contains the DISQUSWIDGETS.displayCount method.

// Change what DISQUSWIDGETS.displayCount does.
var actualDisplayCount = DISQUSWIDGETS.displayCount;
DISQUSWIDGETS.displayCount = function(options) {
    // do things with options
    return actualDisplayCount(options);
};

// Now load the source from http://forum.disqus.com/count-data.js?q=1&1=2,http://www.website.com&2=2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM