Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook comments plugin - same comments on every page

Facebook comments on my website work well except the fact when someone comments on one article that same comment shows up on every article on the website. Obviously, I don't want that. What I did is basically copy and paste code offered on developers.facebook.com:

      `<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";
      fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));</script>`


     `<div class="fb-comments" data-href="http://example.com" data-num-posts="2" data-                                      width="470"></div>`

What did I do wrong? I would appreciate any help.

Vio

like image 407
Vioresin Sinani Avatar asked Nov 29 '22 09:11

Vioresin Sinani


2 Answers

You using same data-href attribute for comments social plugin on all pages (linking comments to http://example.com)

You should either provide URL of your post or leave this attribute empty (current page URL is used by default if this attribute missing or empty) on each page comments social plugin placed.

like image 96
Juicy Scripter Avatar answered Dec 10 '22 20:12

Juicy Scripter


I have same problem, tried the solution offered by "juicy scripter" and I get "The comments plugin requires an href parameter." Then I found out juicy's solution should work if you use the XFBML version of the plugin.

In any case the solution I implemented on my static php site was to replace the href/URL with this code

    <?php echo('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>
like image 22
Marco Granetto Avatar answered Dec 10 '22 19:12

Marco Granetto