×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Vincenzo Assenza
Added: Sep 25, 2015 3:40 PM
Views: 9
Tags: share magento
  1. <?php
  2. $urlToShare = $_product->getProductUrl();
  3. $image = $this->helper('catalog/image')->init($_product, 'image');
  4. if (strlen($urlToShare) > 140):
  5.     $urlToShare = Mage::getBaseUrl();
  6. endif;
  7. $text = (strlen($urlToShare . ' ' . $productTitle) < 140) ? $urlToShare . ' ' . $productTitle : substr($urlToShare . ' ' . $productTitle, 0, 138) . '..';
  8. $facebookLinkShare = 'http://www.facebook.com/sharer.php?u=' . $urlToShare;
  9. $twitterLinkShare = 'http://twitter.com/home?status=' . urlencode($text);
  10. $pinterestLinkShare = 'http://pinterest.com/pin/create/button/?url=' . $urlToShare . '&media=' . $image . '&description=' . urlencode($productTitle);
  11. $gplusLinkShare = 'https://plus.google.com/share?url=' . $urlToShare;
  12. ?>
  13. <a class="utility-icon sharer sharer-pin" target="_BLANK" href="<?php echo $pinterestLinkShare; ?>"><?php echo $this->__('PIN'); ?></a>
  14. <a class="utility-icon sharer sharer-tw" target="_BLANK" href="<?php echo $twitterLinkShare; ?>"><?php echo $this->__('TWEET'); ?></a>
  15. <a class="utility-icon sharer sharer-fb" target="_BLANK" href="<?php echo $facebookLinkShare; ?>"><?php echo $this->__('SHARE'); ?></a>
  16. <a class="utility-icon sharer sharer-gplus" target="_BLANK" href="<?php echo $gplusLinkShare; ?>"><?php echo $this->__('SHARE'); ?></a>