Skip to content

Instantly share code, notes, and snippets.

@rodrigoea
Last active August 29, 2015 14:05
Show Gist options
  • Save rodrigoea/f04837de84c4c7af1962 to your computer and use it in GitHub Desktop.
Save rodrigoea/f04837de84c4c7af1962 to your computer and use it in GitHub Desktop.
Show number of comments from Disqus

#How to create a box that displays number of comments from Disqus


#1

Create a new application at Disqus Applications.

Get the API Key and Short Name of your application.


#2

In function.js do the following steps:

  • Replace the value of disqusPublicKey by the API Key.
  • Replace the value of disqusShortname by the sort name of your application.

#3

In count.html replace the value of data-disqus-url by the current url.


That's all folks ;D

<a href="#disqus_thread"><span class="show-comments" data-disqus-url="CURRENT_URL">0 Comentários</span></a>
var disqusPublicKey = "Public_key";
var disqusShortname = "short_name";
var threadUrl = 'link:' + $('.show-comments').attr('data-disqus-url');
$.ajax({
type: 'GET',
url: 'https://disqus.com/api/3.0/threads/set.jsonp',
data: { api_key: disqusPublicKey, forum: disqusShortname, thread: threadUrl },
cache: false,
dataType: 'jsonp',
success: function(result) {
if (result.response.length === 1) {
if (result.response[0].posts == 1) {
btnText = result.response[0].posts + ' Comment';
}else{
btnText = result.response[0].posts + ' Comments';
}
$('.show-comments').html(btnText);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment