Facebook Like Count
Asked Answered
V

4

7

I've successfully integrated a Facebook Like button to WordPress based website. The Facebook Like button is shown only on single posts. However, I would like to output how many times a post is being liked on the front page of my site without showing the actual like button. A simple number output is what I'm after.

I've been reading Facebook documentation as well some tutorials that partly deal with this issue, but haven't got anywhere so far.

Vivisection answered 5/6, 2011 at 14:29 Comment(0)
W
11

Paste this function in your theme functions.php file and save the file.

function bfan() {
    $pageID = 'Page ID/Page Vanity URL';
    $info = json_decode(file_get_contents('http://graph.facebook.com/' . $pageID));
    echo $info->likes;
}

Then you can call the function.

You will need to know your facebook page ID or facebook page name,then just substitute it in the code above.

Hope this helps you out.

Warn answered 8/6, 2011 at 15:23 Comment(1)
The JSON method works but there's no more likes in the FB Graph. They put everything together as 'shares', so it would be: echo $info->shares;Rowena
H
9

Facebook has an API for finding out how many Facebook shares (likes etc.) a page has:

http://graph.facebook.com/?ids=https://stackoverflow.com/

Hispidulous answered 7/6, 2011 at 15:29 Comment(1)
Hey @ceejayoz, thanks for the response but I need to have some code hints and/or samples in order to figure out the piece of code required for printing the number of likes in wordpress. Facebook API lacks examples for beginners such as myself, I think. Any code hint or sample you can share?Vivisection
A
4

I found here a simple and great solution: link

Anciently answered 8/12, 2011 at 22:1 Comment(1)
Great link with functions in PHP and ASP. Thank You.Medallist
R
0

If you want see the evolution of your Top Social Stories in your Wordpress, you can use this plugin that tracks data from Facebook, Twitter and Google+ for each post and globally for all the links of your blog and export these data also in custom field to use them in your theme.

UPDATE: this plugin now tracks also Pinterest, Linkedin and Vkontakte and has many new features.

Repugnant answered 29/10, 2013 at 17:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.