所有图片在prettyPhoto中都有相同数量的facebook点赞

All pictures has same amount of facebook likes in prettyPhoto

本文关键字:点赞 facebook 有图片 prettyPhoto      更新时间:2023-09-26

我使用jquery.prettyPhoto在我的网站上显示相册。我激活了social_tools,在每张照片下面显示twitter和facebook小部件。

问题是,如果有人喜欢一张照片,所有其他照片都会得到一个赞,所以每张照片都有234个赞。

这是因为当另一张照片显示时,我的location.href没有改变吗?

激活我的相册的代码是:

$.fn.prettyPhoto({ 
  slideShow: 3000,
  social_tools: ''
    +'<div class="pp_social">'
      +'<div class="twitter">'
        +'<a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a>'
        +'<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>'
      +'</div>'
    +'<div class="facebook">'
      +'<iframe src="http://www.facebook.com/plugins/like.php?locale=nl_NL&href='+location.href+'&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:23px;" allowTransparency="true"></iframe>'
    +'</div>'
  +'</div>'
});

如何解决此问题?

提前谢谢。

我不久前也遇到了同样的问题,尽管没有使用jquery.prettyPhoto。我有一系列对象,每个对象都有一个单独的网页。和你一样,当有人喜欢其中一件物品时,他们每个人都会得到一个赞。

问题是"赞"与同一地址相连,因此被认为是相同的。一旦我们确保它们分别连接到不同的地址,就解决了这个问题。

我编辑了jquery.prettyPhoto插件来解决这个问题。

在替换facebook链接的部分,我添加了一个额外的占位符:

// Rebuild Facebook Like Button with updated href
if(settings.social_tools){
  facebook_like_link = settings.social_tools.replace('{location_href}', encodeURIComponent(location.href)).replace('{image_src}',encodeURIComponent(location.protocol+'//'+location.host+pp_images[set_position])); 
  $pp_pic_holder.find('.pp_social').html(facebook_like_link);
}

额外的占位符是{image_src},并且正在被图像位置替换。

我刚刚做了:

// Rebuild Facebook Like Button with updated href
if(settings.social_tools){
  facebook_like_link = settings.social_tools.replace('{location_href}', pp_images[set_position]);
  $pp_pic_holder.find('.pp_social').html(facebook_like_link);
}

它成功了!

图像url被传递到类似FB的href。现在FB知道这是一个不同的url。