Facebook and Twitter Like and Share, with Counts, in Plain Text (1 post)

  1. danielmichel
    Posted 2 years ago #

    Been trying to figure this out for a couple how now. I think the twitter side of things is working.
    I want to add twitter share, and a facebook like button(not a share button), with like and share counts, in plain text on my site, as seen here.


    function get_tweets($url) {
      $json_string = file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' . $url);
      $json = json_decode($json_string, true);
      return intval( $json['count'] );
    function get_likes($url) {
      $json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);
      $json = json_decode($json_string, true);
      return intval( $json[$url]['shares'] );

    calling it

    <a href="JavaScript:window.open('http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>','','width=657,height=400,scrollbars=1')">Like</a>
    	<a href="JavaScript:window.open('https://twitter.com/share?url=<?php the_permalink(); ?>&text=<?php the_title(); ?>:','','width=450,height=350')">Tweet</a>
    	<?php echo get_tweets("<?php the_permalink(); ?>"); ?>
    	<?php echo get_likes( "<?php the_permalink(); ?>" ); ?>

    Thanks in advance for any help

Topic Closed

This topic has been closed to new replies.

About this Topic