Jump to content
Sign in to follow this  

Most Liked Articles

Recommended Posts

You know how there is the Facebook Like button for each news article? And on the right sidebar how it is sorted by most recent comments?


I think there should be a module/app/whatever that lists them by most liked. Maybe not most liked of all time, but maybe monthly or weekly.

You can use the Facebook JSON API to get the value of each page, and save it somewhere in the database if you don't want to flood Facebook's servers.


What do you think?

Share this post

Link to post
Share on other sites

hmmm that could be doable..... I will have to look into that.

Share this post

Link to post
Share on other sites

// connect
$db = new MySQLi('localhost', 'DB USERNAME','DB PASSWORD');
if ( !$db ) { trigger_error($db->connect_error); exit; }
// select db
// query for all posts
$res = $db->query("SELECT DISTINCT post_id FROM `TABLE` ;");
if ( !$res ) { trigger_error($db->error); exit; }
// process results of first query
while ( $row = $res->fetch_assoc() ) {
$feedURL = "http://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url=%27http://www.overclockersclub.com/news/" . $row['COL OF NEWS ID'] . "%27&format=json";
$data = file_get_contents($feedURL);
$obj = json_decode($data);
$likecount = $obj->{'COL OF LIKE COUNT'};
$sql = sprintf("UPDATE `TABLE` SET `COL` = '%d' WHERE `post_id` = '%d' AND `meta_key` = 'ROW' LIMIT 1 ;", $likecount, $row['COL OF NEWS ID']);
$res2 = $db->query($sql);
if ( !$res2 ) { trigger_error($db->error); exit; }


Hope that helps some. It's what I use on my site. Not sure how the DB is set up for this site, so you would probably have to change a lot. And that's just the cron job to update how many likes there is. But it wouldn't be hard to list by how many likes.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...