How to display facebook fan count in text in your blog

July 1, 2010 by: 2

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.

facebook fan count How to display facebook fan count in text in your blog

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.

facebook developer link option How to display facebook fan count in text in your blog

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.

create application facebook How to display facebook fan count in text in your blog

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.

api keysecret facebook How to display facebook fan count in text in your blog

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 auto submit blog posts to twitter,Facebook,LinkedIn
  2. How to highlight codes& scripts in your wordpress blog posts
  3. How to display recent searches in wordpress blog sidebar
  4. How to make money from facebook.com
  5. Video tutorial-How to migrate blogger blog to wordpress with 301 url redirection
  6. Thesis-how to place ads Above the post title in thesis wordpress theme
Share this Story

AASLIN

Add a Comment on "How to display facebook fan count in text in your blog"

    2 Comments on "How to display facebook fan count in text in your blog"

  1. Adam says:

    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.

  2. accessorize says:

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

Leave a Reply