I would like to have a list of my most liked posts from facebook, and place it in the sidebar. Is there a way for doing it? (and if so, how?)
Leave a Reply
You must be logged in to post a comment.
I would like to have a list of my most liked posts from facebook, and place it in the sidebar. Is there a way for doing it? (and if so, how?)
You must be logged in to post a comment.
A quick google brought up these, which led me to this post.
In other words, 1) queries Facebook for the number of likes, 2) suggests to hook into the ‘liking’ action, counting & logging the ‘likes’ on your site.
Either way you’re going to need to get stuck in to the Facebook API. If you go for 1), you’ll also need the PHP SDK.I’d say 1) would be the better of the two, since it’s non-JavaScript dependent, and getting ‘likes’ from other sources won’t affect it (i.e. people liking your page using means other than the button on your site).
Since it looks like you can only query one page (URL) at a time (unless a Facebook guru can correct me?), you’d need some way of frequently caching the like counts of all your posts.
Perhaps a
wp_cron
function that continually loops over say, 20 posts, every hour (check Facebook usage terms), and updates the like count as a post meta entry.To get the ‘most liked’ posts, you could then simply query posts that have the meta key, and order by the meta value.
You can stick https://graph.facebook.com/ in front of any URL to see how many people liked it. It returns a JSON object with the URL and the number of “shares” for the URL.
Note: An OAuth token is not required to do this. You don’t even have to be logged into Facebook.
Example: https://graph.facebook.com/http://ottopress.com/2011/photo-gallery-primer/
Over time, you can poll those, store the info as meta data, and then order by it.
Related question: Top 3 posts in last week ordered by Facebook and Twitter share counts