I have to display the total number of social shares, like mashable does in it´s website.
It´s not a problem, I found a php code that does the job.
function getTotalShares($atts) {
extract(shortcode_atts(array(
'cache' => '3600',
'url' => 0,
'f' => 0,
'bgcolor' => '#ffffff',
'bordercolor' => '#ffffff',
'borderwidth' => '0',
'bordertype' => 'solid',
'fontcolor' => '#7fc04c',
'fontsize' => '55',
'fontweight' => 'normal',
'padding' => '1'
), $atts));
$shareHash = "$cache.$url.$f.$bgcolor.$bordercolor.$borderwidth.$bordertype.$fontcolor.$fontsize.$fontweight.$padding";
$totalShareRecord = 'totalshares_' . $shareHash;
$cachedposts = get_transient($totalShareRecord);
if ($cachedposts !== false) {
return $cachedposts;
} else {
if (!$url) $url = get_permalink($post->ID);
$json = file_get_contents("http://api.sharedcount.com/?url=" . rawurlencode($url));
$counts = json_decode($json, true);
$return = $counts['Twitter'] + $counts['Facebook']['total_count'] + $counts['GooglePlusOne'];
if ($f) $return = '' . $return . '';
set_transient($totalShareRecord, $return, $cache);
return $return;
}
}
add_shortcode('totalshares','getTotalShares');
Now the problematic!
The code above get the numbers of shares based on the permalink, which is pulled by get_permalink($post->ID);
. My website works as a content aggregator, so I want to pull the number of shares of the original post url, which in my website is filled in the post meta links_link_custom
. My question is: Is this possible?
I hope this text is not confusing, please comment if more information is needed.
I found the solution:
Replace
with