Created
August 21, 2016 07:18
-
-
Save cloverstd/78ae668e8c8106e0ed102b4bf99b91da to your computer and use it in GitHub Desktop.
Ghost Casper Theme 多说评论数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 多说评论数目 | |
$(function() { | |
var threads = []; // thread-key | |
$('.post-title a').each(function(){threads.push($(this).attr('href'))}); | |
if (threads.length > 0) { | |
var duoshuo_api = "https://api.duoshuo.com/threads/counts.jsonp"; | |
var params = { | |
short_name: "sub-domain", // sub-domain.duoshuo.com | |
threads: threads.join(',') | |
}; | |
$.ajax({ | |
url: duoshuo_api, | |
jsonp: "callback", | |
dataType: "jsonp", | |
data: params, | |
success: function( response ) { | |
if (response.code == 0) { | |
$('article.post').each(function(){ | |
var thread = $(this).find('.post-title a').attr('href'); | |
var info = response.response[thread]; | |
var str = '' | |
if (info.comments == 0) { | |
str = 0 + ' comment'; | |
} else { | |
str = info.comments + ' comments'; | |
} | |
$(this).find('footer.post-meta').append('<span class="post-date">' + str + '</span>'); | |
}) | |
} | |
} | |
}); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment