Chapter 5. Social Media and Magento

So, you've begun to develop your own custom Magento 1.8 theme now. Social networks such as Twitter and Facebook are ever popular and can be a great source of new customers if used correctly on your store. This chapter covers the following topics:

  • Integrating a Twitter feed into your Magento store
  • Integrating a Facebook Like Box into your Magento store
  • Including social share buttons in your product pages
  • Integrating product videos from YouTube into the product page

Integrating a Twitter feed into your Magento store

If you're active on Twitter, it can be worthwhile to let your customers know. While you can't (yet, anyway!) accept payment for your goods through Twitter, it can be a great way to develop a long term relationship with your store's customers and increase repeat orders.

One way you can tell customers you're active on Twitter is to place a Twitter feed that contains some of your recent tweets on your store's home page. While you need to be careful not to get in the way of your store's true content, such as your most recent products and offers, you could add the Twitter feed in the footer of your website.

Creating your Twitter widget

To embed your tweets, you will need to create a Twitter widget. Log in to your Twitter account, navigate to https://twitter.com/settings/widgets, and follow the instructions given there to create a widget that contains your most recent tweets. This will create a block of code for you that looks similar to the following code:

<a class="twitter-timeline" href="https://twitter.com/RichardCarter" data-widget-id="123456789999999999">Tweets by @RichardCarter</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

Embedding your Twitter feed into a Magento template

Once you have the Twitter widget code to embed, you're ready to embed it into one of Magento's template files. This Twitter feed will be embedded in your store's footer area. So, so open your theme's /app/design/frontend/default/m18/template/page/html/footer.phtml file and add the highlighted section of the following code:

<div class="footer-about footer-col">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('footer_about')->toHtml(); ?>
<?php 
$_helper = Mage::helper('catalog/category'),
$_categories = $_helper->getStoreCategories();
if (count($_categories) > 0): ?>
<ul>
<?phpforeach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
</li>
<?phpendforeach; ?>
</ul>
<?phpendif; ?>
<a class="twitter-timeline" href="https://twitter.com/RichardCarter" data-widget-id="123456789999999999">Tweets by @RichardCarter</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>

The result of the preceding code is a Twitter feed similar to the following one embedded on your store:

Embedding your Twitter feed into a Magento template

Tip

As you can see, the Twitter widget is quite cumbersome. So, it's wise to be sparing when adding this to your website. Sometimes, a simple Twitter icon that links to your account is all you need!

You could also use a static block in Magento to contain your Twitter feed; refer to Chapter 4, Magento Layout, to see how you can add a static block to a Magento template.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.74.18