1
votes

I'm trying to get the DISQUS comments and comment counts associated with a particular image ID for my PHP site.

1) Get comment count:

To get comment count, I've followed DISQUS' guide, but it just gives me a link to where the comments are on the comic... and not the total number... They say:

Append #disqus_thread to the href attribute in your links. This will tell Disqus which links to look up and return the comment count. For example:

<a href="http://foo.com/bar.html#disqus_thread">Link</a>.

But how would I get that count if my url string was like this:

<a href=".?action=viewimage&site=comics&id=66">Link</a>

So my questions are:

  • Where would I append #disqus_thread?
  • How can I get the comments count from that one comic URL and display those total comments on another page? Why does it just give me a link to the comments and not the comment number for that associated comic?

2) Get specific comments, like most recent or most popular

I haven't really found any documentation on this with the exception of this where they say I'd probably need to write my own script...

Any thoughts?

Thanks!

1

1 Answers

1
votes

The comment counting script will basically look up the thread and return the comment counts that match the URL - so it needs to be an absolute URL for that to work.

Assuming you were looking at this document, you'll also notice that there's an optional data-disqus-identifier attribute you can use, and you would use this in conjunction with a disqus_identifier in your commenting embed code. This will override the URL lookup and it will instead pull comment counts for the identifier. You will still need to append the #disqus_thread anchor to your URL, however.

For the second question, you would need to use the API to code a widget to display comments outside of the embed. There's a couple of different approaches you can take:

  1. Load comments directly from the API using either the posts/listPopular or posts/list endpoints (in conjunction with your disqus_identifier)

  2. Load numerous threads details and use the RSS feed of the latest comments using the threads/set endpoint. You can also use this to get the comment counts directly from the API rather than use the comment counting script.