Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I found a simple solution thanks to this answer: How do I change the singular/plural on “comment” to “comments” on Facebook's number of comments?How do I change the singular/plural on “comment” to “comments” on Facebook's number of comments?

Here is how I solved without the tag, using the code I was already working for, this goes into function.php

function get_likes($url) {
   $json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);
   $json = json_decode($json_string, true);
   $count = intval( $json[$url]['shares'] );
   if ($count == 0) {
     echo "share!";
   } elseif ($count == 1) {
     echo "shared 1 time";
   } else {
   echo "$count shares";
   }
} 

and this in the template

<?php $url = get_permalink( $post_id ); echo get_likes($url); ?>

I found a simple solution thanks to this answer: How do I change the singular/plural on “comment” to “comments” on Facebook's number of comments?

Here is how I solved without the tag, using the code I was already working for, this goes into function.php

function get_likes($url) {
   $json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);
   $json = json_decode($json_string, true);
   $count = intval( $json[$url]['shares'] );
   if ($count == 0) {
     echo "share!";
   } elseif ($count == 1) {
     echo "shared 1 time";
   } else {
   echo "$count shares";
   }
} 

and this in the template

<?php $url = get_permalink( $post_id ); echo get_likes($url); ?>

I found a simple solution thanks to this answer: How do I change the singular/plural on “comment” to “comments” on Facebook's number of comments?

Here is how I solved without the tag, using the code I was already working for, this goes into function.php

function get_likes($url) {
   $json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);
   $json = json_decode($json_string, true);
   $count = intval( $json[$url]['shares'] );
   if ($count == 0) {
     echo "share!";
   } elseif ($count == 1) {
     echo "shared 1 time";
   } else {
   echo "$count shares";
   }
} 

and this in the template

<?php $url = get_permalink( $post_id ); echo get_likes($url); ?>
Source Link
molokom
  • 395
  • 4
  • 18

I found a simple solution thanks to this answer: How do I change the singular/plural on “comment” to “comments” on Facebook's number of comments?

Here is how I solved without the tag, using the code I was already working for, this goes into function.php

function get_likes($url) {
   $json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);
   $json = json_decode($json_string, true);
   $count = intval( $json[$url]['shares'] );
   if ($count == 0) {
     echo "share!";
   } elseif ($count == 1) {
     echo "shared 1 time";
   } else {
   echo "$count shares";
   }
} 

and this in the template

<?php $url = get_permalink( $post_id ); echo get_likes($url); ?>