2014年11月5日 星期三

在blogger文章上加上Facebook 「讚」(like)與 Google Plus +1 按鈕

目前最流行社交網站就是Facebook 與Google+,許多網站現在都會與這些熱門的社交網站結合,增加網站的流量與知名度。

這篇文章要介紹如何在blogger文章加上Facebook [讚]與Google Plus +1按鈕 , 按步驟去修改,就可以簡單而快速增加此功能。



STEP1:
到Blogger管理介面的[範本],點選右上角的[備份/還原],進入之後點選[下載完整範本],並儲存下載檔案,就完成網站備份的動作。




STEP2:
下載的檔案是個XML檔,使用文字編輯軟體來打開。在檔案中找尋</head>」,然後在這個 </head> 之前的</b:temolate-skin>之後加入 Google Plus +1 按鈕要使用的的程式碼:
  </b:template-skin>
  <!-- Begin: Add by ethanwu -->
  <!-- Google Plus +1 button -->
  <!-- Place this tag in your head or just before your close body tag. -->
  <script src='https://apis.google.com/js/plusone.js' type='text/javascript'>
    {lang: &quot;zh-TW&quot;}
  </script>
  <!-- End: Add by ethanwu -->
</head>
程式碼中用 <!-- 與 --> 夾起來的部分(紅色)都是註解,而 Begin: Add by ethanwu 與 End: Add by ethanwu 之間程式就是要加進去的。

SETP3: 

接下來就是按鈕的擺放位置,這個範例是把按鈕放在文章標題的下方,首先尋找<div class='post-header'>,這個 div 就是專門將小工具放在文章標題下方的用的,但是在管理界面中沒辦法放置自定的按鈕。

一樣加入 Begin: Add by ethanwu 與 End: Add by ethanwu 之間的程式碼。

<div class='post-header'>
  <div class='post-header-line-1'/>
  <!-- Begin: Add by ethanwu -->
  <b:if cond='data:blog.pageType != &quot;static_page&quot;'>
    <div class='socialMediaHeader'>
      <!-- facebook like button -->
      <iframe allowTransparency='true' expr:src='&quot;http://www.facebook.com/plugins/like.php?href=&quot; + data:post.canonicalUrl + &quot;&amp;send=false&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=21&quot;' frameborder='0' scrolling='no' style='border:none; overflow:hidden; width:90px; height:21px;'/>

      <!-- Google Plus +1 button -->
      <!-- Place this tag where you want the +1 button to render. -->
      <div class='g-plusone' data-size='medium' expr:data-href='data:post.canonicalUrl'/>
    </div>
  </b:if>
  <!-- End: Add by ethanwu -->
</div>
這個程式碼主要包含了 Facebook 與 Google Plus +1 兩部分,上半部的 iframe 部分是 Facebook 所使用的,下半部的 div 則是 Google Plus +1 按鈕,兩個按鈕<div class='socialMediaHeader'> 包起來,這樣可以方便微調按鈕的位置。

SETP4 :
最後一步驟,到Blogger管理介面的[範本],點選右上角的[備份/還原],把修改之後的檔案上傳回去,就完成了。




沒有留言:

張貼留言