加入各種分享按鈕 (Twitter / Facebook 讚 / 新浪微博分享 / Google PlusOne)

今早懸掛八號風球,看來「李氏力場」失效了,打工仔的夢想,有假放囉。這麼好的消息,一定要在各大微博、Facebook 平台分享!

你的網站增加了一些分享按鈕沒有?以下是常見的一些:

<?php // Google Plusone ?>
<script type="text/javascript">
  window.___gcfg = {lang: 'zh-TW'};

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>
<g:plusone></g:plusone>

<?php // Sina Weibo ?>
<script type="text/javascript" charset="utf-8">
(function(){
  var _w = 90 , _h = 24;
  var param = {
    url:location.href,
    type:'2',
    count:'1',
    appkey:'',
    title:'',
    pic:'',
    ralateUid:'2387284991',
    rnd:new Date().valueOf()
  }
  var temp = [];
  for( var p in param ){
    temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )
  }
  document.write('<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&') + '" width="'+ _w+'" height="'+_h+'"></iframe>')
})()
</script>

<?php // Twiiter ?>
<script type="text/javascript">
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = '//platform.twitter.com/widgets.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>
<a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="notabluescreen">Tweet</a>

<?php // Facebook Like ?>
<div class="fb-like" data-send="true" data-layout="button_count" data-width="250" data-show-faces="true"></div>
<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/zh_TW/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

 

Drupal / Wordpress 使用者

雖然大多 CMS 平台都有各種 Plugins 增加這些按鈕,但可能要安裝數個才能達到目的,過於繁複。倒不如直接貼到模版正確地方來得簡潔。

個人習慣是將代碼存在一個 widget.php 中,然後 include 'widget.php' 進版型中 :)

測試

不妨幫我試一試是否正確,按一按吧:

寫下您的回覆

電子郵件不會公開