codeigniter: facebook social plugin – like button helper

Hello everybody,

I have just created a short helper to create facebook like button dynamically for any content, by just giving-in the URL of the page. Hope this one also helps you like my other helpers :)

Helper function:

  1.  
  2. if(!function_exists(‘facebook_like’)){
  3.  function facebook_like($url){
  4.  $formlink=‘<iframe src="http://www.facebook.com/plugins/like.php?href=’;
  5.   $formlink .= urlencode($url);
  6.   $formlink .= ‘;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>’;
  7.                
  8.   return $formlink;
  9.   }
  10.  }
  11.  

Usage:

  1.  
  2. <?php
  3. $url = current_url();
  4. echo facebook_like($url);
  5. ?>
  6.  

Note:
As you can see the function requires you to use the codeigniter’s native URI helper.

Share