Jump to content

[SOLVED] Add Facebook Comments to CMS page


Recommended Posts

use this code:

<div id="fcbcfooter"><div data-href="http://{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}" class="fb-comments" data-width="500px;" data-num-posts="10"  data-colorscheme="light"></div></div>

 

at the end of cms.tpl file located in your theme directory.

 

of course you can change width (500px) number of posts (10) and color sheme (light / dark)

Link to comment
Share on other sites

you have to add also special code in the page header:

<div id="fb-root"></div>
<script>(function(d, s, id) {
 var js, fjs = d.getElementsByTagName(s)[0];
 if (d.getElementById(id)) return;
 js = d.createElement(s); js.id = id;
 js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=506964709387702";
 fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

 

+ remember to change the 506964709387702 to your appId (but you can use it if you want)

 

is there any chance to check your website? i will do it with pleasure

  • Like 1
Link to comment
Share on other sites

in this case you will have to define if conditions

 

{if $smarty.get.id_cms==3 OR $smarty.get.id_cms==2 OR $smarty.get.id_cms==9}

comments code here

{/if}

 

where the OR $smarty.get.id_cms==2 is an ID number of CMS page

for these pages your comments will appear, for all pages not defined in IF condition facebook comments will not appear

  • Like 1
Link to comment
Share on other sites

Ok something is not right. The code is actually appearing on the webpage now.

 

Can you tell me what I'm doing wrong? Currently I'm working in my cms.tpl file. I've inserted the code at the end of the file because that's where I want the comments to appear. But I only want them to appear on certain CMS pages so I'm trying to write the if/condition rule. When I do, the rule actually appears on the webpage and furthermore the FB Comments still appear on every CMS page.

 

This is the code I'm using right now at the end of the cms.tpl file

 

{literal}
<div id="fb-root"></div>
<script>(function(d, s, id) {
 var js, fjs = d.getElementsByTagName(s)[0];
 if (d.getElementById(id)) return;
 js = d.createElement(s); js.id = id;
 js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=93355466934";
 fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
{if $smarty.get.id_cms==3 OR $smarty.get.id_cms==14 OR $smarty.get.id_cms==9}
<div class="fb-comments" data-href="http://www.knittwitt.com/blog" data-width="470"></div>
{/if}
{/literal}

Link to comment
Share on other sites

use this code:

{if $smarty.get.id_cms==3 OR $smarty.get.id_cms==14 OR $smarty.get.id_cms==9}
{literal}
<div id="fb-root"></div>
<script>(function(d, s, id) {
 var js, fjs = d.getElementsByTagName(s)[0];
 if (d.getElementById(id)) return;
 js = d.createElement(s); js.id = id;
 js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=93355466934";
 fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-comments" data-href="http://www.knittwitt.com/blog" data-width="470"></div>
{/literal}
{/if}

 

now it will work because {if} conditions are out off the {literal} tags

 

{literal} tag means that smarty syntax will not be "compiled" so you see the code in the page body.

  • Like 1
Link to comment
Share on other sites

Thanks Vekia as always!

 

I have it figured out I believe! Finally!

 

The main problem I discovered is that using the FB comments code on the cms.tpl file will put the FB comments box on EVERY CMS page. So it'll appear on any page you create using the CMS module in the BO. But that's not what I wanted in this situation. I only wanted the FB Comments box to appear on specific pages. To achieve this I used an updated code and put it at the end of the page inside html code of the CMS page I created. You have to remove the literal tags once you do so because as Vekia stated they show up on the page.

 

Doing it this way is more time consuming because it means that I'll need to adapt the code every time I create a new CMS page that I want the FB comments box on. But, applying the code in the cms.tpl (as I originally wanted) will not only put the box on every page, but every comment will appear as the same on every CMS page. So for example, if you put "testing" in the FB comments box on the Terms & Conditions page...the FB comment box on the "About us" page will also display "testing".

 

The only work around that I've found so far is putting the html code on each individual page. If someone has a better way I'm all ears!

 

Thanks again Vekia!

Link to comment
Share on other sites

yea thanks for explanation, im convinced that your solution will be heplful for all merchants here with similar problem.

I think that this topic is a nice know-how, i will create in nearest future little tutorial about that - whole topic is worth it!

Link to comment
Share on other sites

  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...