Adding Facebook plugin comments for dynamic produc

2019-03-16 11:12发布

I installed facebook comments on my website. My website is a dynamic website and pages are like this www.example.com/page?id=54, www.example.com/page?id=67.

If I post a comment in this page: www.site.com/page?id=54, it also appears in www.example.com/page?id=67. The comments are not unique for a page, but appear in every page

i saw the question : Facebook comments, for each page. The answer in this question is that the problem is because of the "?" sign. It seems that "?" sign in the URL make it broken for the Facebook plugin. And I need to change form of URl writing.

Because my website is 7 years old have incoming links to it, I don’t want to change the method of the URl writing .

is there another way to fix it?

4条回答
We Are One
2楼-- · 2019-03-16 11:29

When inserting the widget to your page you add something similar to the following code:

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

You need to replace http://example.com each time for the new page, once with ?id=54 and another time with ?id=67 for each relevant page.

查看更多
何必那么认真
3楼-- · 2019-03-16 11:43

If you're using PHP this is the code which will request the URL of the current page and then link Facebook comments to it:

<?PHP    
$url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
echo "<div class='fb-comments' data-href='$url' data-num-posts='10' data-width='470'></div>";
?>

It works if your dynamic content has only one query string (for example ?product=). If it has more query strings for the same page, for example &sort= for sorting options, then it won't work properly as the Facebook comment which would appear on sorting option ascending wouldn't appear on the sorting option descending, for example.

You can solve this part by assigning a base URL for that product and then showing the FB comments for that URL on all dynamic pages with that product. For example, you're requesting FB comments for the page ?product=13&sort=asc&type=34 even if &sort and &type are different on that page.

查看更多
看我几分像从前
4楼-- · 2019-03-16 11:46

Firstly, copy comment div and script from Facebook, paste it to your product details page:

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

and

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

Finally, simply add this code:

<script>
    $(".fb-comments").attr("data-href", window.location.href);
</script>
查看更多
【Aperson】
5楼-- · 2019-03-16 11:47

Hmm, I'm confused. You say the site is 7 years old and you cannot change it, but somehow you recently inserted the like plugin into an unchangeable web site. Now you want ways to fix this unchangeable website.

But, if you could change the website, here's what you're going to need to do:

  1. Put in the required og meta tags into the <head> section of each web page as described on the like plugin documentation web site. You can do this programmatically via the query string parameter using your .asp coding skills.
  2. Test/QA the OG meta tags are correctly specified at https://developers.facebook.com/tools/lint
  3. Add the required html code for the plug in and ensure the href correctly and fully identified in the data-href parameter of the like plug
  4. Test/QA the like button by viewing source on the page being sent down.

EDIT

Take a look at what Facebook sees for your url

http://developers.facebook.com/tools/debug/og/echo?q=http%3A%2F%2Fwww.winebar.co.il%2Fproduct.asp%3Fproductid%3D567%26CatCode%3D182

Notice the plugin code

BAD: data-href="http://winebar.co.il/product.asp?productid="

If should look like the URL in the user's browser bar:

GOOD: data-href="http://www.winebar.co.il/product.asp?productid=567&CatCode=182"

查看更多
登录 后发表回答