0

How do I get facebook share buttons that look like those on this page http://greyenlightenment.com/real-estate-palo-alto-vs-everywhere-else/

and have the share counters as well? I have spent over a day looking for nice share buttons to no avail. Most buttons are too big or don't count the number of Facebook shares. Can someone find me a simple php script that can do this

2 Answers2

0

For Buttons you need this code:

Note: get_permalink() and get_the_title() is WordPress function that retrieve link of current page and title of current page.

.share-button {
  font-family: sans-serif;
  display: inline-block;
  padding: 7px 10px;
  border: 1px solid #EEE;
  border-radius: 3px;
  background-color: #FAFAFA;
  color: #656565;
  text-decoration: none;
}

.share-button:hover {
  border: 1px solid #999;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
}

.share-button span {
  display: inline-block;
  margin-right: 10px;
  color: red;
}
<a class="share-button" href="http://www.facebook.com/sharer/sharer.php?u=<?php echo get_permalink();?>&amp;t=<?=urlencode(get_the_title());?>" target="_blank"><span id="share-facebook">0</span>Facebook</a>

<a class="share-button" href="http://www.twitter.com/intent/tweet?url=<?php echo get_permalink();?>&amp;text=<?=urlencode(get_the_title());?>" target="_blank"><span id="share-twitter">0</span>Twitter</a>

<a class="share-button" href="http://plus.google.com/share?url=<?php echo get_permalink();?>" target="_blank"><span id="share-gplus">0</span>Google Plus</a>

For count share page, you need API Key and insert return into each, like #share-facebook etc... see more how to get share on this discussion Getting the Facebook like/share count for a given URL

When you have an API key, you are going to make a request and grab shares page number, once you have the object with informations, you add it to your div, something like this:

<script type="text/javascript">
    facebookreturnobject = $.getJSON('https://graph.facebook.c...'); // see examples on discussion above
    $('#share-facebook').text(facebookreturnobject.share.count);
</script>

Do the same for Twitter and Google Plus.

Community
  • 1
  • 1
rafaelfndev
  • 679
  • 2
  • 9
  • 27
  • Requesting the current count should not be done client-side via JS - because you would need to expose an access token in the code. So unless the user logs in on the site so that you can use their user access token, this needs to be done server-side. Plus, it should not be done on every page load, that will make you run into the rate limits pretty quickly. So some form of caching needs to be implemented as well. – CBroe Mar 16 '17 at 11:30
0

There are many plugins for sharing buttons. You just need to choose one. link to the official wordpress site