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:
-
-
function facebook_like($url){
-
$formlink=‘<iframe src="http://www.facebook.com/plugins/like.php?href=’;
-
$formlink .= ‘;layout=button_count&show_faces=true&width=450&action=like&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>’;
-
-
return $formlink;
-
}
-
}
-
Usage:
-
-
<?php
-
$url = current_url();
-
?>
-
Note:
As you can see the function requires you to use the codeigniter’s native URI helper.
Tagged: codeigniter, facebook, facebook helper, facebook like button, facebook social plugins, like button, social plugins
Nice one work for me …
expect other things which i will search..
Thanks thephpx….
edit this to:
function facebook_like($url = false){
if(!$url) $url = current_url();
Then the actual function call can simply be
or
If you want to send in a different url, simply pass it through as the parameter, if not the current url will be used. I have the identical helper on AngelCMS.co.uk and all my sites! (Was looking for something else, found this but thought I could help anyways)
Thanks bro , i like it and was very much useful to me .. thanks
I must be doing something wrong because I see the raw PHP code surrounding the like button on my page. These are the steps I took:
(testing on localhost)
1. copy code as is – paste in a file called facebook_helper.php and save to directory application/helpers/
2. in my controller I’m loading with the call $this->load->helper(‘facebook’);
3. in my view I’m using the code described in the usage box above.
Any help or guidance would be much appreciated. Thanks.
hi there,
the steps looks file, but have you loaded url helper before calling that because if you see it usage the current_url() function which is dependent on the url helper.
thanks,
faisal ahmed
hi Faisal,
Thank you for the reply. I should have mentioned I have the URL helper autoloaded in autoload.php using the following line:
$autoload['helper'] = array(‘url’);
Is there anything else I might be missing? Thanks.
I’m really embarrassed to admit that I had a simple syntax error and it is working fine now…sorry to take up room on the board….Great helper function, thanks for your work and for your help!