Showing posts with label Social sharing buttons on Product page in magento. Show all posts
Showing posts with label Social sharing buttons on Product page in magento. Show all posts

Wednesday 1 October 2014

How to add social sharing buttons on Product Details page in magento


How to add social sharing buttons on Product Details page in magento

There are lots of extension available for social sharing in magento. Here i have make my own social sharing buttons. Just add below code into your view.phtml file.

<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_productName = urlencode(trim($_helper->productAttribute($_product, $_product->getName(), 'name')))?>
<?php $_productImageUrl = urlencode(trim($this->helper('catalog/image')->init($_product, 'image')))?>
<?php $_productUrl = urlencode(trim($_product->getProductUrl()))?>
<?php $_u = 'p[url]=' . $_productUrl . '&p[images][0]=' . $_productImageUrl . '&p[title]=' . $_productName . '&p[summary]=' . urlencode(trim($_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description'))); ?>

Facebook :

<a href="<?php echo 'http://www.facebook.com/sharer.php?s=100&' . $_u; ?>" target="_blank" title="<?php echo $this->__('Share on Facebook') ?>" class="link-facebook"><img src="<?php echo $this->getSkinUrl('images/share_1.png'); ?>" width="81" height="19" alt="" /></a>

Twitter :

<a href="<?php echo 'http://twitter.com/home?status=' . $_productName . '+' . $_productUrl; ?>" target="_blank" title="<?php echo $this->__('Share on Twitter') ?>" class="link-twitter"><img src="<?php echo $this->getSkinUrl('images/share_2.png'); ?>" width="78" height="20" alt="" /></a>

Google plus :

<a href="javascript:popWin('https://plus.google.com/share?url=<?php echo urlencode($_productUrl); ?>', 'google', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes');" title="<?php echo $this->__('Share on Google Plus') ?>"><img src="<?php echo $this->getSkinUrl('images/share_3.png'); ?>" width="59" height="20" alt="" /></a>

Pinterest :

<a href="javascript:popWin('https://pinterest.com/pin/create/button/?url=<?php echo urlencode($_productUrl); ?>&media=<?php echo urlencode($_productImageUrl); ?>&description=<?php echo urlencode($_productName); ?>', 'pinterest', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes');" title="<?php echo $this->__('Pin it') ?>"><img src="<?php echo $this->getSkinUrl('images/share_4.png'); ?>" width="59" height="20" alt="" /></a>


Thats it enjoy chandresh rana coding... :)