Next I'm trying to put just one share count I've had on Facebook in the loop of my theme. For this I found the following function and tried to modify it for my need.
Follow the function:
function ia_fb_count($url_post) {
//Get the transient value from database
$fbcount = get_transient( 'fblcount' );
if ( empty( $fbcount ) ){
//If no value stored, get the like count
$file = file_get_contents("http://graph.facebook.com/?ids=$url_post");
$jd = json_decode($file);
$fbcount = number_format($jd->{'shares'});
// Set the facebook likes transient value for 24 Hours
set_transient('fblcount', $fbcount, 60*60*24 );
// Also, return it at the same time
return $fbcount;
} else {
// Transient Value is present, return it
return $fbcount;
}
}
How do I call the function in my theme:
<?php
$url_post = the_permalink();
echo ia_fb_count($url_post);
?>
Could anyone help me?