Last active
December 15, 2015 09:58
-
-
Save Neolot/5241844 to your computer and use it in GitHub Desktop.
WORDPRESS Количество лайков по URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Кол-во лайков по URL | |
*/ | |
function getFBLikes($postID){ | |
$cache = get_transient('likes_' . $postID); | |
if ( empty( $cache ) ){ | |
$url = get_permalink($postID); | |
$result = json_decode(file_get_contents("http://api.facebook.com/method/fql.query?query=select%20total_count%20from%20link_stat%20where%20url='$url'&format=json"));; | |
set_transient('likes_' . $postID, $result[0]->total_count, 3600); | |
return $result[0]->total_count; | |
} else { | |
return $cache; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment