简体   繁体   中英

Disqus comment count for multiple pages

The following code is to get Disqus counts of comments for multiple pages.

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.

Is there any javascript code which will get just the comments?

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.


edit

To filter by id , in this case 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:

// 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM