Adding Facebook 'Like' button to your Drupal site

I wanted to look at integrating the Facebook 'Like' button on individual nodes (including a list of nodes using views). I ran across a few resources and found a good starting point. My approach embeds the code within node-{content type}.tpl.php.

Here's my approach...

Code:

<iframe id="iframe_like" name="fbLikeIFrame_0" class="social-iframe" scrolling="no" frameborder="0" src="http://www.facebook.com/widgets/like.php?width=100&amp;show_faces=1&amp;layout=standard&amp;colorscheme=light&amp;href=<?php $curr_url = check_plain("http://" .$_SERVER['HTTP_HOST'] .$node_url); echo $curr_url; ?>" width="100%" height="30"></iframe>

  1. Find and open the node.tpl.php file in your theme folder. If you want to add the like button to each and every node, then edit this file. If you want to add it to certain content types, then you can open that specific node.tpl.php file or simply copy this file and rename to node-{insertContentTypeHere}.tpl.php (for a content type of Video, your file will be named node-video.tpl.php. If that was confusing to you, leave a comment and I'll try to explain further.
  2. We will want to insert the code above between <div class="content"> and <?php print $content ?>
  3. Save and upload your modified file to your server.

You can test it out on using the LIKE button on the top right of this post. Go ahead, give it a shot!

The Facebook like button has two color options. Light and Dark. You can switch by modifying the code above from colorscheme=light to colorscheme=dark.

Also check out Adding Twitter button to your Drupal site.

Tags: 

11 Comments

Hi, I'm trying to add a fb

Hi,

I'm trying to add a fb like button to my node view page (view-view-unformatted--new.tpl.php) and with your code, I can see the button and it appears to run fine, but when I click the button, innitialy it shows '1' person like and disapears in a second, then I go to my fb wall and I can't see the new. ¿How can I do? ¿Any reason for this?

Sorry for my poor english and thanks in advance.

Dani.

do you have a how to guide

do you have a how to guide for computer dummies like myself?
I cannot understand your instructions. I know i have a drupal site and can add text but have tried adding the like button a million times to no avail.
all i get is exposed html code...no button

This method works but is very

This method works but is very simple in its nature because you are liking the entire site instead of a particular node. Do you have a means of pointing a user from facebook to a unique url on a drupal site?