Advertisement
wdtobibur

Share Count in WordPress

Oct 16th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. code pase functions.php
  2.  
  3. $facebook_like_share_count = function ( $url ) {
  4.  
  5. $api = file_get_contents( 'http://graph.facebook.com/?id=' . $url );
  6.  
  7. $count = json_decode( $api );
  8.  
  9. return $count->shares;
  10. };
  11.  
  12. $twitter_tweet_count = function ( $url ) {
  13.  
  14. $api = file_get_contents( 'https://cdn.api.twitter.com/1/urls/count.json?url=' . $url );
  15.  
  16. $count = json_decode( $api );
  17.  
  18. return $count->count;
  19. };
  20.  
  21. $pinterest_pins = function ( $url ) {
  22.  
  23. $api = file_get_contents( 'http://api.pinterest.com/v1/urls/count.json?callback%20&url=' . $url );
  24.  
  25. $body = preg_replace( '/^receiveCount\((.*)\)$/', '\\1', $api );
  26.  
  27. $count = json_decode( $body );
  28.  
  29. return $count->count;
  30.  
  31. };
  32.  
  33. $google_plusones = function ( $url ) {
  34. $curl = curl_init();
  35. curl_setopt( $curl, CURLOPT_URL, "https://clients6.google.com/rpc" );
  36. curl_setopt( $curl, CURLOPT_POST, 1 );
  37. curl_setopt( $curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]' );
  38. curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
  39. curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Content-type: application/json' ) );
  40. $curl_results = curl_exec( $curl );
  41. curl_close( $curl );
  42. $json = json_decode( $curl_results, true );
  43.  
  44. return intval( $json[0]['result']['metadata']['globalCounts']['count'] );
  45. };
  46.  
  47.  
  48. show file....
  49. $url = get_permalink( $post_id ) echo $facebook_like_share_count ("$url") ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement