4

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

Vioresin Sinani
  • 41
  • 1
  • 1
  • 2

9 Answers9

12

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.

Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
  • i put http://example.com/some/page. But it becomes http://example.com at the iframe. But +1 for you because i ended up removing the data-href attribute. – Fandi Susanto Aug 05 '15 at 15:08
4

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']); ?>
4

Don't use the root url for the data-href. You need to generate the url for each page dynamically. E.g. if this was a WordPress blog, you would use php code data-href="<?php echo(get_permalink()) ?>"

Christian
  • 332
  • 1
  • 7
  • 19
Nani Kani
  • 51
  • 2
1

This would work fine, but I found that in one site I could not use PHP. So This worked for me as a javscript solution. Simple replace the comments div with this javascript code...

<script>document.write("<div class='fb-comments' data-href='" + window.location.href + "' data-num-posts='2' data-width='470'></div>");</script>
b_uk_happy
  • 478
  • 4
  • 13
1

Try This:

< div class="fb-comments" expr.href='data:post.url' data-width="600" data-numposts="5" data-colorscheme="light">

NOte:

in the above line in between < and div there is no space.

paste this code just above to

class='post-footer-line post-footer-line-3

Check in: http://debaonline4u.blogspot.com

Debashis Sahoo
  • 5,388
  • 5
  • 36
  • 41
1

I put the page url after the domain and it's work for me. MyDomain is the domain I out when I create the code on the Facebook comments.

<div class="fb-comments" data-href="http://MyDomain/Mypage URL" data-numposts="5" data-colorscheme="light"></div>
Hilal
  • 49
  • 5
1

The problem is data-href.

Use dynamic URL instead.

For eg. If you want Facebook comment for every page separately.

PHP :

data-href="<?php echo 'http://'. $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; ?>"

Hope it help someone.

Umar Sid
  • 1,317
  • 1
  • 17
  • 24
0

Due to the need to have separation of concerns...."data-href" tag is there to serve...

For example: if you have some page www.example/123.com,,,, your data-href value must be www.example/123.com....

For doing this means is that render and store comments for www.example/123.com and it will not then appear on other pages....

Suhail Mumtaz Awan
  • 3,295
  • 8
  • 43
  • 77
0

Use this for for PHP Laravel.

$currentURL = URL::current();//get currnt url
<div class="comment-form-area">
                        <div class="sharethis-inline-reaction-buttons"></div>
                        <div class="fb-comments" data-href="{{$currentURL}}" data-width="700" data-numposts="5">
                        </div>
                    </div>

if you use in Laravel Blade Templates do this.

@php $currentURL = URL::current(); @endphp
<div class="comment-form-area">
                        <div class="sharethis-inline-reaction-buttons"></div>
                        <div class="fb-comments" data-href="{{$currentURL}}" data-width="700" data-numposts="5">
                        </div>
                    </div>
Aum Zagri
  • 137
  • 1
  • 5