Facebook Comments PHP class is used to easily enable visitors of your web site to write comments on articles, photos or any other content on your web site, and share them with their friends by posting them on their profiles. Posting a comment on user's wall will result in more visitors from the Facebook to your site.

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.


Comments Image

Following image represents the default Facebook Comments control, which is one of the most often used controls on web sites.

facebook comments

Usage Example

The example shows default Facebook Comments control 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 Comments PHP class with blue color.

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

            $comments = new Comments();
            $comments->Render();
        ?>
        </body>
</html>



Facebook Bookmark 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 Comments Demo page.


Configuration

Configuration of the Facebook Comments PHP class is done through calls of the setter methods, which in turn set the private properties. For Facebook Comments 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 comments php
Method Name
Type
Description
facebook comments php
SetUniqueId
String
Function sets the unique Id of the comments box. Default value is encoded page URL. It's required only if more than one comments box is used on the same page.
facebook comments php
SetWidth
Int
Function sets the width in pixels. Default value is 550.
facebook comments php
SetCommentsCount
Int
Function sets the maximum number of displayed comments. Default value is 10.
facebook comments php
SetColorScheme
Int
Function sets the color scheme. Available values are 'light' and 'dark'. Deault value is 'light'
facebook comments php
SetUrl
String
Function sets the URL of the comments. If it's not set, current page URL is used.