Facebook Like button allows users to share some content from the website with their friends. Pressing on the Like button will result in publishing of a story on user's profile, with link to the website. Increasing number of links will results in more visitor to the site from Facebook, and also better ranking in search engines.

This class is a member of Facebook Connect PHP Toolkit. To see all classes from the toolkit, please look at the Facebook Connect Graph API classes.


Like Button Image

Following image represents the default Facebook Like Button, which is the most used control on web sites.

facebook like button


PHP Example

The example shows default Facebook Like Button, which is shown on picture above. The example shows the code of whole page, but important content is highlighted: required includes and initialization for any page with brown color, and working with Facebook Like Button PHP class with blue color.

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
       <title>Facebook Like Button PHP Example</title>
    </head>
    <body>
        <?php
            require_once 'facebook.php';
            require_once 'faceconn/faceconn.php';
            UseGraphAPI();

            $like = new LikeButton();
            $like->Render();
        ?>
        </body>
</html>



Facebook Like Button PHP class has a demo page inside Demo Website where it can be seen how it works. The most important fact is that the Demo website is contained in package with Facebook Connect PHP Toolkit which is very useful resource of code examples for each control from the toolkit. Look at the Facebook Like Button Demo page.


Configuration

Configuration of the Facebook Like Button PHP class is done through calls of the setter methods, which in turn set the private properties. For Facebook Like Button PHP class, there are no required properties to set. All you have to do is to create new instance of the class and call Render() method. All properties from the list below are optional.

facebook like button php
Method Name
Type
Description
facebook like button php
SetUrl
String
Function sets the URL of the like button. If it's not set, current page URL is used.
facebook like button php
SetLayout
String
Function sets the layout. Available values are 'standard', 'button_count' and 'box_count'. Default value is 'standard'.
facebook like button php
SetShowFaces
Bool
Call this function with the parameter set to true to show profile picture bellow the like button. Default value is true.
facebook like button php
SetWidth
Int
Function sets the width of the like button in pixels. Default value is 450.
facebook like button php
SetAction
String
Function sets the text of the like button. Available values are 'like' and 'recommend'. Defined text is translated depending on user language settings.
facebook like button php
SetFont
Int
Function sets the font inside the like button. Available values are 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms' and 'verdana'.
facebook like button php
SetColorScheme
String
Function sets the color scheme. Available values are 'light' and 'dark'. Deault value is 'light'.
facebook like button php
SetRef
Int
Function sets the reference string for tracking referals.