Skip to content

Instantly share code, notes, and snippets.

@cloverstd
Created August 21, 2016 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloverstd/78ae668e8c8106e0ed102b4bf99b91da to your computer and use it in GitHub Desktop.
Save cloverstd/78ae668e8c8106e0ed102b4bf99b91da to your computer and use it in GitHub Desktop.
Ghost Casper Theme 多说评论数
// 多说评论数目
$(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