所有图片都有相同数量的脸书喜欢prettyPhoto
问题描述:
我正在使用jquery.prettyPhoto在我的网站上显示相册。我激活了social_tools
以在每张照片下方显示twitter和facebook小部件。所有图片都有相同数量的脸书喜欢prettyPhoto
问题是,如果有人喜欢一张照片,所有其他照片都喜欢,所以每张照片有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+'&layout=button_count&show_faces=true&width=500&action=like&font&colorscheme=light&height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:23px;" allowTransparency="true"></iframe>'
+'</div>'
+'</div>'
});
我怎样才能解决这个问题?
在此先感谢。
答
我编辑了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}
并且正在由所述图像位置取代。
答
前段时间我有同样的问题,虽然没有使用jquery.prettyPhoto。我有一系列的对象,每个对象都有一个单独的网页。和你一样,当有人喜欢其中一个物体时,他们每个人都会喜欢它。
问题是,“喜欢”被链接到相同的地址,因此被认为是相同的。一旦我们确定他们每个链接到不同的地址,它就解决了这个问题。
答
我只是做:
// 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);
}
和它的工作!
图像网址像href一样传递给FB。现在FB明白这是一个不同的网址。
图像'src'的图像'id'是否有占位符(或类似的东西)? – 2012-08-03 08:10:56