How to diaply Facebook Like It button in Joomla

Many people are having problems with getting the current URL in Joomla CMS and calling Facebook's IFrame with a Like It button. Here is a quick tutorial that might help.

 

Get teh current URL

<?php $currentUrl = JURI::getInstance()->toString();

Then replace few characters in the url

$currentUrl = str_replace('&', '%26', $currentUrl);
$currentUrl = str_replace('=', '%3D', $currentUrl);
$currentUrl = str_replace(':', '%3A', $currentUrl);
$currentUrl = str_replace('//', '%2F%2F', $currentUrl);
$currentUrl = str_replace('?', '%3F', $currentUrl); 
?>

Then simply paste the FB like it IFrame like this

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo $currentUrl; ?>&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>