DISQUS commenting system is nice. API is confusing me a bit, so if anyone can please guide me to the right directions.
What I want to do is to get the total number of comments from dynamic pages/posts and insert that number to a MySQL table so I can filter the posts of those pages according to the total comments number and display each post's comment number in the forontapage, sidebars etc. Of course, I would like to update those rows later with a function I'll create when new comments pop up. But what I am asking is just the way I can get them.
Below my disqus_indentifier:
var disqus_identifier = <?php echo $post_id ?>;
Thanks!
As you discovered, the Disqus comment count script is definitely the best solution for what you're trying to do. It doesn't require any API integration or database work. Simply paste the code on your site and it will automatically find the counts for all comment count links on the page and show the relevant Disqus comment count for each.
For anyone looking to do more granular work along these lines via our API, the best endpoint would probably be threads/details which returns the details for a thread (including the number of comments). As far as inserting that information into your database I'd recommend looking over basic SQL INSERT documentation.
We've also put together some sample API recipes which can help you jumpstart your API integration, including a threads/details PHP script.
Related
I have to add the custom Post id for the custom post type. can anyone help me?
Check screen short for more details. http://prntscr.com/mo3eyu
This is a work around that works.
Background info:
We maintain a few almost identical web pages with different branding. The code repo is shared across these. The developers hard coded page IDs into the PHP in the past. I was asked to add new pages. After adding new pages on each website, I noticed the IDs were all randomly generated. This was breaking PHP code's logic. So, I needed to edit these IDs just like OP.
The work around:
In WP web admin page, there's an export / import functionality under tools menu. The new pages should be created in one site, then exported / imported onto other websites. This way, page IDs don't get created randomly. It copies the IDs from the exported page. So you can have same IDs on all pages.
PS:
Not sure why the past developers decided to hard-code page IDs in the code. This shouldn't have been the case to start with. When you don't have much time to refactor everything, stack overflow always comes to help.
IDs determine post record storage in database, changing them directly would be highly prone to breaking things. For example extensions often store IDs as a way to refer to specific post and do something with it.
The simple way to change to some ID would be to just create a new post and copy data over (through admin or with code either).
Post ID of a post also reflect in tables other than Post table, like post comments table. Changing post ID will disturb the relationship of post table with other tables, so it is not advisable.
I'm trying to get the comment count on a WordPress post as a PHP variable.
For some reason comments aren't syncing properly between disqus and WordPress so get the comment count from WordPress locally isn't an option.
Does anyone have any ideas about how to go about this? There's an API and PHP wrapper but I'd like to see if there's an easier way before I get stuck into the API.
Thanks!
PS I need as a PHP variable so posts can receive an rating based on likes, favourites and comments so getting it in JS isn't really an option.
Thanks!
I don't think you have other options to get the data on the server side other than using the Disqus APIs.
I think that the correct API for doing this is: http://disqus.com/api/docs/threads/set/
You can understand how it works from this example in JS: http://help.disqus.com/customer/portal/articles/1131783-tutorial-get-comment-counts-with-the-api the results are the same, so it should be your code.
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:
Link.
But how would I get that count if my url string was like this:
Link
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!
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:
Load comments directly from the API using either the posts/listPopular or posts/list endpoints (in conjunction with your disqus_identifier)
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.
This is really a point me in the right direction question. What path should I take if I want to display the number of page views each gallery page receives?
Retrieve Google Analytics Data via PHP, or
Capture the page views directly on my pages with my own PHP and mySQL setup?
Seems, like number 1 would be the better choice. I just don't know how difficult this option will be. Any insights on this?
Option 2 is definitely simpler.
If you do figure out how to get the page results out of Google Analytics, they will not be up-to-date. It takes Google at least several hours before the page views show up.
That also depends if You want to have info on more questions (statistics). I often use custom setup to track such things cause I can later use some data to do statistics about users actions.
For example, You want to give users (owners of photos) info about witch users (male or female, 30+ or below 30, and so on) are viewing. How many guests, how many registered users. There are tons of data You can retrive by building custom system.
It all depends on what You want to have at the end.
I suspect that if You want to have only raw data about number of users You coud somehow parse data from Google Analytics as well.
And as posted below. Google have to take time to update, custom setup not.
I tried with graph api asked many things to there but none of them are returns comments.
I want to get all comments, and put in a separate page for search engines to scan and index.
comments are very rich full and I want them
You can retreive comments (actually posts and their comments) from the Comments plugin from this api url:
https://graph.facebook.com/comments/?ids={$url_of_your_page}
please see the documentation here: http://developers.facebook.com/docs/reference/fql/
the table you need to query is this here:
http://developers.facebook.com/docs/reference/fql/comment/
(it is also one of the first examples)
the key is that you can specify an identifier for every comment plugin that you embed. using this identifier you can then select comments using the graph api.
regarding search engines you should not make the impression that you are serving different content to the spiders than to the users so it would probably be a good idea to load the comments over the api by default (please cache them) and then replace it by the javascript box if javascript is available, so the users can write new comments.
even better (in my opinion) would be always to display the comments in html in your website and only load the facebook comments plugin if the user wants to make a new comment. but that probably requires one additional step for the user.
you can also read about the ajax chrawling scheme
If you want to use the graph API what you do is grab the comment ID in the json (the very first number you see and it appears as {user_id}_{status_message_ID} example: 1234_5678910) and then have https://graph.facebook.com/{the number you got}?access_token={access token}
Do reduce strain what you could do is run the system that you do to put all the status messages and comments onto your website (for instance a 'for each' or 'while' statements etc) then add an 'if' statement that says if count (under comments on the json) is more than 3 it'll retrieve the json for that post using the id and spit out your data.
I hope this was of some help. Please say if you want anything explained further.
Regards,
Jon
You can use this url to get comments of an url and paginate them:
?fields=og_object{comments.order(reverse_chronological).limit(10).after(NgZDZD)}&id={YOUR_URL}
Even It works with latest(v2.10) graph version.