Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

Social Share Buttons

By: Twansparant on Jan 14th, 2013  |  syntax: PHP  |  size: 2.88 KB  |  views: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. // Social Sharing
  3. function social_share_buttons($postid, $facebook, $twitter, $linkedin, $googleplus, $pinterest) {
  4.  
  5.         $twitteraccount = 'Username';
  6.         $postlink = get_permalink($postid);
  7.         $posttitle = get_the_title($postid);
  8.         $postimageid = get_post_thumbnail_id($postid);
  9.         $postimage = wp_get_attachment_image_src($postimageid, 'full');
  10.        
  11.         /* Facebook Like Button */
  12.         if ($facebook && $facebook == true) : ?>
  13.                 <div class="facebook-share-button">
  14.                         <iframe src="http://www.facebook.com/plugins/like.php?app_id=179762912095902&amp;href=<?php echo $postlink; ?>&amp;send=false&amp;layout=button_count&amp;width=120&amp;show_faces=false&amp;action=like&amp;locale=<?php echo get_locale(); ?>&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe>
  15.                 </div>
  16.         <?php endif;   
  17.        
  18.         /* Tweet Button */
  19.         if ($twitter && $twitter == true) : ?>
  20.                 <div class="twitter-share-button">
  21.                         <a class="twitter-share-button" href="http://twitter.com/share" data-url="<?php echo $postlink; ?>" data-text="<?php echo $posttitle; ?>" data-count="horizontal" <?php if($twitteraccount) { ?> data-via="<?php echo $twitteraccount ?>" <?php } ?>>Tweet</a>
  22.                         <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
  23.                 </div>
  24.         <?php endif;
  25.        
  26.         /* Linkedin Share Button */
  27.         if ($linkedin && $linkedin == true) : ?>
  28.                 <div class="linkedin-share-button">
  29.                         <script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
  30.                         <script type="IN/Share" data-url="<?php echo $postlink; ?>" data-counter="right" data-showzero="true"></script>
  31.                 </div>
  32.         <?php endif;
  33.        
  34.         /* Google Plus One Button */
  35.         if ($googleplus && $googleplus == true) : ?>
  36.                 <div class="plusone-button">
  37.                         <!-- Place this tag where you want the +1 button to render. -->
  38.                         <div class="g-plusone" data-size="medium" data-href="<?php echo $postlink; ?>"></div>
  39.                         <!-- Place this tag after the last +1 button tag. -->
  40.                         <script type="text/javascript">
  41.                           (function() {
  42.                             var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
  43.                             po.src = 'https://apis.google.com/js/plusone.js';
  44.                             var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  45.                           })();
  46.                         </script>
  47.                 </div>
  48.         <?php endif;
  49.        
  50.         /* Pinterest Pin Button */
  51.         if ($pinterest && $pinterest == true) : ?>
  52.                 <div class="pin-it-button">
  53.                         <a href="http://pinterest.com/pin/create/button/?url=<?php echo $postlink; ?>&media=<?php echo $postimage[0]; ?>&description=<?php echo $posttitle; ?>" class="pin-it-button" count-layout="horizontal" always-show-count="1"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
  54.                         <script type="text/JavaScript" src="http://assets.pinterest.com/js/pinit.js"></script>
  55.                 </div>
  56.         <?php endif;
  57.        
  58. } ?>