【发布时间】:2017-03-16 05:56:28
【问题描述】:
如何获得与本页 http://greyenlightenment.com/real-estate-palo-alto-vs-everywhere-else/ 类似的 Facebook 分享按钮
还有股票计数器吗?我花了一天多的时间寻找漂亮的分享按钮,但无济于事。大多数按钮太大或不计算 Facebook 分享的数量。有人能帮我找到一个可以做到这一点的简单 php 脚本吗
【问题讨论】:
如何获得与本页 http://greyenlightenment.com/real-estate-palo-alto-vs-everywhere-else/ 类似的 Facebook 分享按钮
还有股票计数器吗?我花了一天多的时间寻找漂亮的分享按钮,但无济于事。大多数按钮太大或不计算 Facebook 分享的数量。有人能帮我找到一个可以做到这一点的简单 php 脚本吗
【问题讨论】:
对于按钮,您需要此代码:
注意:get_permalink() 和 get_the_title() 是 WordPress 函数,用于检索当前页面的链接和当前页面的标题。
.share-button {
font-family: sans-serif;
display: inline-block;
padding: 7px 10px;
border: 1px solid #EEE;
border-radius: 3px;
background-color: #FAFAFA;
color: #656565;
text-decoration: none;
}
.share-button:hover {
border: 1px solid #999;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
}
.share-button span {
display: inline-block;
margin-right: 10px;
color: red;
}
<a class="share-button" href="http://www.facebook.com/sharer/sharer.php?u=<?php echo get_permalink();?>&t=<?=urlencode(get_the_title());?>" target="_blank"><span id="share-facebook">0</span>Facebook</a>
<a class="share-button" href="http://www.twitter.com/intent/tweet?url=<?php echo get_permalink();?>&text=<?=urlencode(get_the_title());?>" target="_blank"><span id="share-twitter">0</span>Twitter</a>
<a class="share-button" href="http://plus.google.com/share?url=<?php echo get_permalink();?>" target="_blank"><span id="share-gplus">0</span>Google Plus</a>
对于计数分享页面,您需要 API 密钥并在每个页面中插入返回,例如 #share-facebook 等...查看更多如何在此讨论中获得分享 Getting the Facebook like/share count for a given URL
当您拥有 API 密钥时,您将发出请求并获取共享页码,一旦您拥有包含信息的对象,就将其添加到您的 div 中,如下所示:
<script type="text/javascript">
facebookreturnobject = $.getJSON('https://graph.facebook.c...'); // see examples on discussion above
$('#share-facebook').text(facebookreturnobject.share.count);
</script>
对 Twitter 和 Google Plus 做同样的事情。
【讨论】:
有很多分享按钮的插件。你只需要选择一个。 link to the official wordpress site
【讨论】: