如何在我的网站上添加分享按钮?

时间:2017-11-29 07:08:54

标签: php facebook hyperlink share-button

我的网站为每个用户生成一个唯一的ID或链接,以便我如何添加分享按钮以让用户在FB中分享他的链接? 我的网站生成的代码是:

$uid_code = md5($user);

echo '<br /><center><div id="codewrap">Copy link and share it <br /><code>'.$sksiteurl.'index.php?nav=test&id='.$uid_code.'</code></div></center>';

2 个答案:

答案 0 :(得分:0)

供参考使用此链接:

https://www.daddydesign.com/wordpress/how-to-create-a-custom-facebook-share-button-with-a-custom-counter/

<?php
function fb_count() {
global $fbcount;
$facebook = file_get_contents('http://api.facebook.com/restserver.php?method=links.getStats&urls=https://www.daddydesign.com/how-to-create-a-custom-facebook-share-button-with-a-custom-counter/');
$fbbegin = '<share_count>'; $fbend = '</share_count>';
$fbpage = $facebook;
$fbparts = explode($fbbegin,$fbpage);
$fbpage = $fbparts[1];
$fbparts = explode($fbend,$fbpage);
$fbcount = $fbparts[0];
if($fbcount == '') { $fbcount = '0'; }
}       
?>

这会对你有所帮助! 感谢

答案 1 :(得分:0)

首先在您要添加共享链接的位置放置一个按钮,如下所示

<button class="social" data-url="$add-your-page-url" title="Share on Facebook">
    <i class="fa fa-facebook"></i>
</button>

现在通过这个jQuery,您可以共享任何页面链接

<script>

$(document).on('click','.social',function(e){
    var url  = $(this).data("url");
    if(type=="fb")  var url = 'http://www.facebook.com/sharer.php?u=';
    mini=true&url=';
    window.open(url,'',"width=500,height=500,left=400px,top=100px,location=no");
});

</script>

试试这个。