3
Next I’m trying to put only a count of the shares I had on Facebook on loop of my theme. For this I found the following function and tried to modify it to my need.
Follows 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 I call the function in my theme:
<?php
$url_post = the_permalink();
echo ia_fb_count($url_post);
?>
Could someone help me?
@Qmechanic73 more in my theme is not showing the Shared count but the url link.. see image: http://www.tickimg.com.br/uploads/_url_faceboo.jpg I need only the facebook Shared count to appear
– Luciano Oliveira Lima
@Qmechanic73 continues calling not only the numbering but the entire http://localhost/wordpress/? p=368851,588 .. I think this function is not catching the link going through Thema.. in $url_post .. I just don’t know how to do it and how to!
– Luciano Oliveira Lima
Doing this manually returns some result?
– stderr
@Qmechanic73 is returning this error: http://localhost/wordpress/? p=36885 Warning: file_get_contents(http://graph.facebook.com/?ids=): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in C: xampp htdocs wordpress wp-content themes brasilseries functions.php on line 135
– Luciano Oliveira Lima
It must be because you are misformulating the url, see if that knack works.
– stderr