【问题标题】:Simple Facebook + Twitter wordpress share buttons简单的 Facebook + Twitter wordpress 分享按钮
【发布时间】:2017-03-16 05:56:28
【问题描述】:

如何获得与本页 http://greyenlightenment.com/real-estate-palo-alto-vs-everywhere-else/ 类似的 Facebook 分享按钮

还有股票计数器吗?我花了一天多的时间寻找漂亮的分享按钮,但无济于事。大多数按钮太大或不计算 Facebook 分享的数量。有人能帮我找到一个可以做到这一点的简单 php 脚本吗

【问题讨论】:

    标签: wordpress facebook


    【解决方案1】:

    对于按钮,您需要此代码:

    注意: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();?>&amp;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();?>&amp;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 做同样的事情。

    【讨论】:

    • 请求当前计数不应通过 JS 在客户端完成 - 因为您需要在代码中公开访问令牌。因此,除非用户登录网站以便您可以使用他们的用户访问令牌,否则这需要在服务器端完成。另外,它不应该在每次页面加载时都完成,这会让你很快遇到速率限制。因此,还需要实现某种形式的缓存。
    【解决方案2】:

    有很多分享按钮的插件。你只需要选择一个。 link to the official wordpress site

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      • 2016-01-06
      • 1970-01-01
      • 1970-01-01
      • 2011-11-25
      • 2015-09-09
      • 1970-01-01
      相关资源
      最近更新 更多