How to display facebook fan count in text in your blog

Adding facebook fan count to your website or blog may be a best way to promote your blog and to show off your quality to visitors and making them to join as a fan.Facebook has various uses and now it has also come out as an commercial spot for making money and driving more visitors to blogs.Hence this tutorial of adding a facebook fan count text widget in your wordpress blog will be useful for this cause to enable fast loading text fan count.

How to add facebook fan count in text in wordpress blog?

There are three steps that you need to complete enabling facebook fancount in text.This can be used in wordpress or any php powered website.This uses the Facebook api key to display the fan count in text.

STEP 1:

1.Getting your facebook api key,application secret and page id:
You have to sign into facebook first and then click on developers link on the side bar.If you have not signed up for developer in facebook do it here.

2.Now after you click developer option then go to “setup new application” and enter any name and create a application.we are not creating a real application but we need that for getting facebook api keys and application secret.

3.After you click “create application” you will see the api key,application id and secret in the next page.Make a note of it.

4.Visit your facebook fan page and check the url bar to get your fan page id.If you have changed the url to short then goto facebook pages and edit the required page and then see the url bar to get your page id.
http://www.facebook.com/pages/edit/?id=XXXXXXX

STEP 2:

Get the facebook.php file from here.It is the Facebook API PHP SDK file .Then place it in the root  of your website.

STEP 3:

This is the final step showing the fan count as text in your website.You have to place the below in code in your php file.In custom_functions.php for thesis wordpress theme.Be sure to edit the following details before you paste the code and save.
Line 4 – Replace app_id with your Facebook Application ID.
Line 5 – Replace secret_key with application Secret.
Line 10 – Replace the last page_id with your Facebook Fanpage ID.

Now the code is

<?php
require_once('facebook.php');
$facebook = new Facebook(array(
'appId'  => 'app_id',
'secret' => 'secret_key',
'cookie' => true,
));
$result = $facebook->api(array(
'method' => 'fql.query',
'query' => 'select fan_count from page where page_id = page_id;'
));
$fb_fans = $result[0]['fan_count'];
?>

After you are done,save it and now to display the fan count text widget use this code

<?php echo $fb_fans; ?>

Now you have successfully added facebook fancount in text in your blog or website.

Related posts:

  1. How to make money from facebook.com
  2. How to display recent searches in wordpress blog sidebar
  3. Download chitchat for facebook-Desktop chatting Software
  4. How to create a group in facebook
  5. How to decrease wordpress blog loading time compressing css files
  6. How to highlight codes& scripts in your wordpress blog posts
  7. How to be unblocked from facebook restrictions
  8. Scroll/back to top plugin for wordpress blog
  9. How to backup your wordpress blog using SyncbackSE
  10. Video tutorial-How to migrate blogger blog to wordpress with 301 url redirection

{ 2 comments… read them below or add one }

1 Adam July 25, 2010 at 6:13 pm

I get a parse error.

Parse error: syntax error, unexpected T_NEW in public_html/facebook.php on line 4

What if you don’t have thesis theme? Can you put the code in the normal functions.php file that any wordpress theme has?

Thanks.

Reply

2 accessorize August 20, 2010 at 9:34 pm

I know this stuff.It’s one of the best I’m sure!

Reply

Leave a Comment

Previous post:

Next post: