2

I'm trying to make the Facebook Comment Social Plugin here to work with my Ajax jQuery call under Wordpress but unsucessfully.

I am calling a page via jQuery load() after I click on a link. This brings me all the content from that page. I've tried the following already:

Adding the code below in the loaded page or in the original page (the one that calls):

<div class="fb-comments" data-href="<?php echo $commentsFB; ?>" data-num-posts="5" data-width="500"></div>

If I add it in the original page, the comment box shows but I don't want it to show right away, I only want it to show when the user clicks on a link! What can I do to make it work? I tried to hide the box via jQuery with (field).hide() but it doesn't work, it shows either way.

If you want an example http://dev.bsides.co/wasabi/gol/goleiros/ (click on the blue names)

Rafael 'BSIDES' Pereira
  • 2,951
  • 5
  • 22
  • 24

3 Answers3

3

Use FB.XFBML.parse(); after ajax call to regenerate comment box.

it is already posted here

Different Facebook comment box after each ajax call

Community
  • 1
  • 1
Mohd Shahid
  • 1,538
  • 2
  • 33
  • 66
1

Just found a faster way to change the comments, just changing the href:

    $(".fb-comments").attr('data-href', data_href);
    FB.XFBML.parse();
Arik
  • 43
  • 5
0

Well I just figure it out. I need to make a call and render it when I click the link. Then, I also re-parse the Facebook stuff and hide the old Facebook comment if it existed. It's way simpler showing my function that changes once the hash on url changes:

$("#goleirosAjax")
    .animate({opacity: "0.5"})
    .html('<p>Loading...</p>')
    .load(url, function() {
        $("#goleirosAjax").animate({opacity: "1"});
        $('.fb-comments').hide();
        $('#goleirosAjax').after('<div class="fb-comments" data-href="'+ window.location.href +'" data-num-posts="5" data-width="500"></div>');
        FB.XFBML.parse($('#goleirosAjax'));
    });
Marcelo Diniz
  • 2,493
  • 2
  • 21
  • 27
Rafael 'BSIDES' Pereira
  • 2,951
  • 5
  • 22
  • 24
  • Better yet, delete the like with the hide() function, put it out of the click funcion and let it only inside the bind on hashtag change of url. Then, instead of hide(), use remove() so you'll have a cleaner code :) – Rafael 'BSIDES' Pereira Dec 02 '11 at 04:59