Adding Social Networking Buttons to Magento

// February 17th, 2010 // Magento

I have been building a magento based site over the past few months for a new project I am working on with Ruth. The end product will be an online food store that sell Australian Gourmet Foods.

I spent a while searching around Google trying to figure out how to add social networking buttons into the products page. I basically wanted people to click “Share on Facebook”, “Tweet This” and more recently “Buzz This” and send the product name, the URL and any other text I wanted.

All you really need to know is

  • <?php echo $this->htmlEscape($_product->getName()) ?> – Product name
  • <?php echo $_product->getProductUrl() ?>- Product URL

I have added the below to the view.phtml page, found in templates/catalog/product.

Twitter

<a title=”Send this page to Twitter!” href=”http://twitter.com/home?status=Check out the <?php echo $this->htmlEscape($_product->getName()) ?> at <?php echo $_product->getProductUrl() ?> @foodoAU” target=”_blank”><img src=”YOUR BUTTON HERE” alt=”Follow foodoAU on Twitter”/></a>

Facebook

<a href=”http://www.facebook.com/sharer.php?u=<?php echo $_product->getProductUrl() ?>&t=Check+this+out” target=”_blank” title=”Share on Facebook”><img src=”YOUR BUTTON HERE” alt=”Share on Facebook”></a>

Google Buzz

<a href=”http://www.google.com/reader/link?url=<?php echo $_product->getProductUrl() ?>&title=<?php echo $this->htmlEscape($_product->getName()) ?>&srcURL=YOUR URL&srcTitle=YOUR SITE NAME” target=”_blank” rel=”nofollow external” title=”Google Buzz This”><img src=”YOUR BUTTON” ” alt=”Google Buzz This!” /></a>



5 Responses to “Adding Social Networking Buttons to Magento”

  1. Toni Anicic says:

    Nice, clean and easy implementation, good job :)

  2. Rick Pickett says:

    If you want to share the exact page you’re on, you need to get the variable for the current url and then call that variable in place of getUrl.

    more info here: http://snippi.net/magento-get-current-url

  3. Terme says:

    Hi,

    I have an ecommerce website with magento and I want to add facebook and twitter buttons to the home page. I have the “link” from facebook I need to add but I have no idea where I’m supposed to input that information to make the button show up on the main page. HELP PLEASE!

    Thanks! :)

  4. Daniel says:

    @rick – thanks I will take a look!!

    @Terme – did you get this sorted out? If not drop me an e-mail, happy to help.

    Thanks

Leave a Reply