rboyart Posted June 3, 2013 Share Posted June 3, 2013 Hi, I'm looking to add the number of my facebook's fans into my prestashop template. As a smarty variable, so it updates everytime. I have found some code to do it in php : <?php require_once('facebook.php'); $facebook = new Facebook(array( 'appId' => 'your_app_id', 'secret' => 'your_app_secret', 'cookie' => true, )); $result = $facebook->api(array( 'method' => 'fql.query', 'query' => 'select fan_count from page where page_id = your_page_id;' )); $fb_fans = $result[0]['fan_count']; ?> or simpler : <?php $page_id = "XXXXXXXXXXXX"; $xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("a lot"); $fans = $xml->page->fan_count; echo $fans; ?> What's the best way to add the PHP to the smarty template .tpl ? for then use the variable to show the data ? Thanks for any help, Rodrigo Link to comment Share on other sites More sharing options...
vekia Posted June 3, 2013 Share Posted June 3, 2013 it depends on where you want to display it. Generally speaking - in my opinion - it's better to NOT use php code in the smarty files (for now it isn't possible - {php} {/php} doesnt work now) so, you have to add php code to the controller / class (it depends on place, where you want to display likes count) then you can add variable with counter to the smarty array - this will allow you to use it in .tpl file if it is possible - please let me know where you want to display it - and i will show you the guide to achieve what you want :-) regards Link to comment Share on other sites More sharing options...
rboyart Posted June 4, 2013 Author Share Posted June 4, 2013 Hi Vekia, I want to show it in the footer, so I was thinking to simple customize the footer.tpl, or I can do a module to hook to the footer too. I'm trying to achieve this footer as exemple : http://www.archiduchesse.com/ Thanks for your help. regards Link to comment Share on other sites More sharing options...
vekia Posted June 4, 2013 Share Posted June 4, 2013 okay, so i will show you how to implement this without module one last thing: what PS version you use? Link to comment Share on other sites More sharing options...
rboyart Posted June 4, 2013 Author Share Posted June 4, 2013 I'm using PrestaShop™ 1.5.4.1 Thanks Link to comment Share on other sites More sharing options...
vekia Posted June 4, 2013 Share Posted June 4, 2013 okay i've got simplest method than yours: go to the file: classes/controller/FrontController.php add somewhere in the class this function: public static function fbcount($idpage){ $ch = curl_init("http://graph.facebook.com/$idpage"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $raw = curl_exec($ch); curl_close($ch); $data = json_decode($raw); return $data->likes; } then in the footer.tpl file you can use this: {FrontController::fbcount('399888213399907')} where the 399888213399907 is id of your page enjoy! Link to comment Share on other sites More sharing options...
rboyart Posted June 4, 2013 Author Share Posted June 4, 2013 It works like charm ! I didn't know about cURL Functions Easy and effective. Thank you very very much, R Link to comment Share on other sites More sharing options...
vekia Posted June 4, 2013 Share Posted June 4, 2013 You're welcome :-) This method is easiest that method with facebook api & soap calls No app id, no worries it works like a charm as you said :-) so, now i can mark this thread as solved regards 1 Link to comment Share on other sites More sharing options...
ILMP Posted June 22, 2013 Share Posted June 22, 2013 okay i've got simplest method than yours: go to the file: classes/controller/FrontController.php add somewhere in the class this function: public static function fbcount($idpage){ $ch = curl_init("http://graph.facebook.com/$idpage"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $raw = curl_exec($ch); curl_close($ch); $data = json_decode($raw); return $data->likes; } then in the footer.tpl file you can use this: {FrontController::fbcount('399888213399907')} where the 399888213399907 is id of your page enjoy! Hello Vekia, Thanks a lot for this code method.... i have a little question ... for the same likes count for each page product or any page, what is the solution ? I need to create a little button with the like for each product with url. Thank you again Matias Link to comment Share on other sites More sharing options...
ILMP Posted June 22, 2013 Share Posted June 22, 2013 I have try many many link options ... does not work :-( on the internet, I found 1000 different options ..... -_- Help Friends :-) Link to comment Share on other sites More sharing options...
vekia Posted June 22, 2013 Share Posted June 22, 2013 you can use the same method but with modifications, sorry to bother you, but your question isn't the same as main case in this thread - so if it is possible, please create new thread with your question and i will write solution especiall for you Link to comment Share on other sites More sharing options...
ILMP Posted November 16, 2013 Share Posted November 16, 2013 Hello Vekia, Finally the code works well for Facebook Likes... Thanks ! I need now the same for the send Count (Facebook) and maybe you have for the twitter count ? Thank you again. Matias Link to comment Share on other sites More sharing options...
vekia Posted November 16, 2013 Share Posted November 16, 2013 I need now the same for the send Count (Facebook) and maybe you have for the twitter count ? hmm you mean about shares? or ... ? and about twitter? followers? or what? Link to comment Share on other sites More sharing options...
ILMP Posted November 16, 2013 Share Posted November 16, 2013 Thank you Vekia ! For Facebook i need Shares count (Like is OK with your first code) And for tweeter i need Tweet Count for the button in each page product (Not Follow) Thank you very much Matias 1 Link to comment Share on other sites More sharing options...
vekia Posted November 17, 2013 Share Posted November 17, 2013 in facebook shares, wall entries, comments and likes are merged to one value (only fanpage likes are separated). today is a bit late here in europe, but tommorow i will check twitter widgets, will see what i can do Link to comment Share on other sites More sharing options...
ILMP Posted November 17, 2013 Share Posted November 17, 2013 Ok Vekia Thanks Link to comment Share on other sites More sharing options...
vekia Posted November 17, 2013 Share Posted November 17, 2013 Ok Vekia Thanks ok, i've got it! public static function tcount($url){ $ch = curl_init("http://urls.api.twitter.com/1/urls/count.json?url=$url"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $raw = curl_exec($ch); curl_close($ch); $data = json_decode($raw); return $data->count; } + in template file to disply "tweets" count for each page in the shop, use this: {FrontController::tcount("{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}")} Link to comment Share on other sites More sharing options...
ILMP Posted November 18, 2013 Share Posted November 18, 2013 Great ! Merci vekia ! I try your code this night ... Matias Link to comment Share on other sites More sharing options...
vekia Posted November 18, 2013 Share Posted November 18, 2013 Great ! Merci vekia ! I try your code this night ... Matias it this is not what you're looking for - just let me know 'll see what I can do 1 Link to comment Share on other sites More sharing options...
ILMP Posted December 1, 2013 Share Posted December 1, 2013 hello Vekia, Sorry for my late reply ! The Twitter Count bubble works very well. Thank you very much Matias 1 Link to comment Share on other sites More sharing options...
ILMP Posted December 2, 2013 Share Posted December 2, 2013 next time, I'll ask you the same code for the Facebook Like / Send ... Link to comment Share on other sites More sharing options...
vekia Posted December 2, 2013 Share Posted December 2, 2013 as far as i remember, here is a solution for facebook likes (like/send have got the same counter in facebook og api) Link to comment Share on other sites More sharing options...
Arlulo Posted January 20, 2016 Share Posted January 20, 2016 Hi, I tried to use this on a 1.6 installation but nothing happens. Anyone have used this on 1.6? Thank's in advance Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now