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&show_faces=1&layout=standard&colorscheme=light&href=<?php $curr_url = check_plain("http://" .$_SERVER['HTTP_HOST'] .$node_url); echo $curr_url; ?>" width="100%" height="30"></iframe>
- 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.
- We will want to insert the code above between <div class="content"> and <?php print $content ?>
- 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.
11 Comments
I will be modifying my
Submitted by Jerry on
I will be modifying my tutorial to support the same type of button as shown in the top left of the page. Stay tuned.
Have you done this? I'd love
Submitted by Mtro (not verified) on
Have you done this? I'd love to see it- that style doesn't mess with the theme as much.
Check out the new blog post I
Submitted by Jerry on
Check out the new blog post I made about adding both Twitter and Drupal button, exactly how I have it on this website: http://www.jerryjr.com/adding-twitter-and-facebook-buttons-your-drupal-site
it already says...2 people
Submitted by mohanish (not verified) on
it already says...2 people like it.....even if i m goin to b d first person to like it......
it already hve like even if i
Submitted by mohanish (not verified) on
it already hve like even if i m goin to b d first person to like it
do we need to enable any
Submitted by Anant (not verified) on
do we need to enable any modules for it?
Nope!
Submitted by Jerry on
Nope!
Geez, this is the most
Submitted by Valters Boze (not verified) on
Geez, this is the most perfect implementation for me :) sooo simple :D
Hi, I'm trying to add a fb
Submitted by Dani (not verified) on
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
Submitted by lisa (not verified) on
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
Submitted by Joseph (not verified) on
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?