简体   繁体   English

多个页面的Disqus评论数

[英]Disqus comment count for multiple pages

The following code is to get Disqus counts of comments 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}
        ]
    });
}

I want to get just the number of comments example from here: 我想从这里获取评论示例的数量:

{"reactions":0,"uid":1,"comments":2} the number of comments should be 2. {"reactions":0,"uid":1,"comments":2}评论数应为2。

Is there any javascript code which will get just the comments? 是否有任何仅能获得注释的javascript代码?

If you are able to rewrite this as such: 如果您可以这样重写:

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);
}

Then you will be able to access the count like this: 然后,您将可以像这样访问计数:

disqus_options.counts[0].comments

which has the value 2 in this case. 在这种情况下,其值为2


edit 编辑

To filter by id , in this case id == 3 . 要按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.

edit 编辑

You can "hack" the displayCount method: 您可以“破解” 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