0

i need to add facebook comment to each of my Products page i'm using asp.net and my Products page url like this (mydomail.com/Products.aspx?id=5) is there any way to do this

kiro karam
  • 99
  • 1
  • 9

2 Answers2

3

Similar to the Facebook Like button, the Facebook comments plugin is associated with a URL -- it's what makes it unique.

Since you're using an id parameter in your URL, simply pass in your URL to the comments plugin. That should make it so that every page has a unique set of comments.

For example, on products page 5 you could do:

<div class="fb-comments" data-href="<?php echo 'http://myurl.com?id=' . $_GET['id']; ?>" data-width="470" data-num-posts="2"></div>

You'll of course want to make sure that you've dropped in the Facebook Javascript SDK snippet (I'd recommend loading this into the top of your HTML body dynamically):

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

There are other types of plugins that you can use (XFBML, IFRAME), and everything is documented here.

Nick Parsons
  • 8,377
  • 13
  • 48
  • 70
  • but id parameter is changed dynamically – kiro karam Jan 16 '13 at 03:31
  • @user1982250 Totally. Make sure that you're loading in that comments code on every page, and then just swap out your URL dynamically. I'd imagine that you have access to the GET variable? Pardon my PHP, but you would simply do something like data-href="". Modified my example. – Nick Parsons Jan 16 '13 at 03:39
  • yes exactly that what i want but plz can you give me the asp.net code – kiro karam Jan 16 '13 at 03:58
  • Not familiar with asp.net. Regardless of the language, it's a pretty simple approach -- you need to pull the id GET variable from your query string. Simple search returned this: http://stackoverflow.com/questions/1033548/retrieve-get-variables-from-url-in-aspx – Nick Parsons Jan 16 '13 at 04:22
0

use FB.XFBML.parse() after your new facebook plugin

Nishant Dubey
  • 2,802
  • 1
  • 13
  • 18