This class enables the owners of web sites to connect it to their Facebook Page, so they can gain more Likes from their own website. Visitor of web site can easily become a fan of the Facebook Page; see messages from the page wall, their friends which like it too, and the rest of the fans.

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


Like Box Image

Following image shows 3 like boxes. The first one is the default, with 10 fans, show stream and show header. The second one is without fan list, and the third one is without fans and stream.

facebook like box


PHP Example

The example shows PHP code that creates three Facebook like boxes from 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 Box 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 Box</title>
    </head>
    <body>
        <?php
            require_once 'facebook.php';
            require_once 'faceconn/faceconn.php';
            UseGraphAPI();

            // create instance of the class and set pageId
            $likeBox = new LikeBox();           
            $likeBox->SetPageId("185550966885");

            // render the default control on the page
            $likeBox->Render();

            // render without fan list
            $likeBox->SetFansCount(0);
            $likeBox->Render();

            // render without fan list and stream
            $likeBox->SetShowStream(false);
            $likeBox->Render();
        ?>
        </body>
</html>



Facebook Like Box 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 Box Demo page.


Configuration

Configuration of the Facebook Like Box PHP class is done through calls of the setter methods, which in turn set the private properties. For Facebook Like Box PHP class, there is only one mandatory and couple of optional properties to set. After the configuration is set, all you have to do is to call Render() method, and the control will display on page.

Mandatory Properties

facebook like box php
Method Name
Type
Description
facebook like box php
SetPageId
String
Function sets the Facebook Page ID.


Optional Properties

facebook like box php
Method Name
Type
Description
facebook like box php
SetWidth
Int
Function sets the width of the like box in pixels. Default value is 292.
facebook like box php
SetFansCount
Int
Function sets the number of fans to display. Default value is 10.
facebook like box php
SetShowStream
Bool
Call this function with the parameter set to true to show the massages from the Page Wall.
facebook like box php
SetShowHeader
Bool
Call this function with the parameter set to true to show the header.
facebook like box php
SetFont
Int
Function sets the font inside the like button. Available values are 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms' and 'verdana'.