像按钮一样插入facebook [英] Inserting facebook like button

查看:115
本文介绍了像按钮一样插入facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个使用自定义cms的博客网站http://www.example.com,并且我希望网站中的每个内容都显示一个赞按钮.我已经能够添加一个在每个页面中插入代码段的mod,并添加类似代码,但是我该如何区分每个不同帖子中的喜欢",因为正如我记得,facebook类代码需要src="http://www.example.com",如何我如何使每个页面的src值唯一,例如src="http://www.example.com/news/a_news.php".我该如何实现...?

Say I have a blogging site http://www.example.com using custom cms, and I want each content in the site to display a like button. I have been able to add a mod that inserts code snippets in each page, incliding the like code, but how do I go about differentiating the likes from each different post because as I recall, the facebook like code requires a src="http://www.example.com", how do I make the src value unique for each page like src="http://www.example.com/news/a_news.php". How do I achieve this...?

推荐答案

请参考下面的URL为页面生成类似按钮. http://developers.facebook.com/docs/reference/plugins/like/

refer below URL to generate like button for your page. http://developers.facebook.com/docs/reference/plugins/like/

设置完成后,将获得如下所示的代码(SDK脚本+按钮代码).

Once you are done with settings get Code (SDK script + button code) which looks like below.

like按钮代码 http://www.site.com/news/a_news.php

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

<div class="fb-like" data-href="http://www.site.com/news/a_news.php" data-send="false" data-layout="box_count" data-width="450" data-show-faces="true"></div>

现在您必须为每个链接动态设置类似按钮的代码.

now you have to dynamically set up like button code for each link.

b_news.php按钮的说明将

say for b_news.php button will be

<div class="fb-like" data-href="http://www.site.com/news/b_news.php" data-send="false" data-layout="box_count" data-width="450" data-show-faces="true"></div>

对于c_news.php按钮将为

for c_news.php button will be

<div class="fb-like" data-href="http://www.site.com/news/c_news.php" data-send="false" data-layout="box_count" data-width="450" data-show-faces="true"></div>

您只需要在like按钮中更改data-href =并全部设置即可.

you just have to change data-href= in like button and all set.

这篇关于像按钮一样插入facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆