Inserting facebook like button

让人想犯罪 __ 提交于 2019-12-22 22:47:10

问题


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...?


回答1:


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

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

like button code for URL 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.

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>

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>

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



来源:https://stackoverflow.com/questions/7980943/inserting-facebook-like-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!