I need to keep facebook like and share for each individual articles posted by various users. Once i logged in to the site and give share to the particular article it should get shared in facebook as well as it should show the count near to the share button of that individual article.....below is my coding please help me to get rid of this problem.Thanks a lot!
function selfURL() {
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
return
$protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) {
return substr($s1, 0, strpos($s1, $s2));
}
<div id="fb-root">
</div>
<script src="http://connect.facebook.net/en_US/all.js#appId=204703199589477&xfbml=1">
</script>
<fb:like href="<?php print(selfURL()); ?>" send="false" width="90" show_faces="false" action="like" font="" layout="button_count">
</fb:like>
</div>
Include the JavaScript on your page once, ideally right after the opening <body>
tag.
<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/nl_NL/all.js#xfbml=1&appId=182934585182826";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
Place the code for your plugin wherever you want the plugin to appear on your page.
<div class="fb-like" data-href="http://www.test.com" data-send="true" data-width="450" data-show-faces="true"></div>
Replace http://test.com
with the URL of your Article. If you pase the DIV 3 time
As for the Share button, you'll need this piece of script. Yet again, change the domain to your article url
<div class="fb-send" data-href="http://example.com"></div>