Add comments to Facebook plugin for dynamic products

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

If I post a comment on this page: www.site.com/page?id=54, it will also appear on the website www.example.com/page?id=67. Comments are not unique to the page, but are displayed on each page.

I saw a question: Facebook comments for each page . The answer in this question is that the problem is related to "?" sign. It seems that "?" log in the url so that it breaks for the Facebook plugin. And I need to change the spelling of URl.

Since my site has inbound links to it for 7 years, I don’t want to change the method of writing URl.

is there any other way to fix it?

+4
source share
4 answers

First, copy the div and script comment from Facebook, paste it into the 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, just add this code:

 <script> $(".fb-comments").attr("data-href", window.location.href); </script> 
+11
source

If you use PHP, this is the code that asks for the URL of the current page and then links 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>"; ?> 

This works if your dynamic content contains only one query string (e.g. product =). If it has more query lines for the same page, for example, & sort = to sort the parameters, then this will not work as the Facebook comment, which will be displayed when sorting in ascending order, will not be displayed in the descending sort option , for example.

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

+3
source

When you insert a widget into 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> 

Do you need to replace http://example.com each time with a new page, once with? id = 54 and at another time with? id = 67 for each corresponding page.

+1
source

Hm, I'm confused. You say that the site is 7 years old and you cannot change it, but somehow you recently introduced such a plug-in to an immutable website. Now you need ways to fix this immutable website.

But if you can change the site, here is what you need to do:

  • Insert the necessary meta tags in the <head> section of each web page, as described on the documentation web site for such a plugin. You can do this programmatically using the query string parameter using your .asp coding skills.
  • Test / QA OG meta tags are correctly referenced at https://developers.facebook.com/tools/lint
  • Add the required html code for the connection and make sure that href is correctly and fully identified in the data-href parameter of a similar plug
  • Test / QA is a similar button, scanning the source on the page sent down.

EDIT

See 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

Pay attention to the plugin code

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

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

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

0
source

Source: https://habr.com/ru/post/1392913/


All Articles