Facebook Like Button for Drupal
The Facebook Like button is showing up everywhere. And while it may seem simple to put it on your Drupal nodes and pages, it's a little trickier than normal.
You can't just put a piece of javascript in a .tpl file like you can with the old Facebook Share widget, because you need to dynamically pass the URL of the current page yourself.
But it's easy to accomplish. The following is for Drupal 6.
First, put the following code in a module. If you already have a custom module for type of stuff, just stick it at the bottom of that. If not, you'll need to create your own custom module. Don't be intimidated. It takes just a few minutes.
function _module_facebook_like() {
print '<div class="facebook-like"><iframe src="http://www.facebook.com/plugins/like.php?href=' . $_SERVER['HTTP_HOST'] . request_uri() . '&layout=standard&show_faces=false&width=400&action=like&font=arial&colorscheme=light&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:400px; height:35px;" allowTransparency="true"></iframe></div>';
}
Just replace "module" with your module name. You can change the width and the height attributes to suite your purpose.
Now you can call this function in any .tpl file.
Wherever you want the button to show up, just put this code:
<php if (page != 0) {
_module_facebook_like();
} ?>
We wrap it in an "if" statement because we don't want the like button showing up on pages that display teasers. This would just get confusing for users by seeing 6 or 7 Like buttons.
Why is there no module on Drupal.org for this yet? From what I can tell, the Drupal.org site maintainers want it to be rolled into one of the other Facebook modules. But those modules are overkill for someone who just want the dang Like button on their Drupal site.
More Services
Archive
- July 2010 (2)
- December 2009 (2)
- November 2009 (2)
- September 2009 (2)
- July 2009 (2)

