不要再說用百度分享就可以,是可以,但我有我的想法和初衷,而說這話的人都沒有看到!
筆者建站一年多,剛開始用了 JiaThis 分享按鈕,接觸不久,就知道了百度分享,用百度分享一直到現在,所以對 JiaThis 也沒有太多的感覺。
百度分享,為您帶來更多流量!我信了,就用了。看重百度強大的中文搜尋引擎,能給網站帶來流量,但其實與其它分享按鈕沒有太多的區別,別人不分享,再強大的分享按鈕放在那也是個擺設。
自定義分享按鈕有幾個初衷:
- 1 、分享按鈕外掛很強大,幾乎包括所有的社交網站,但載入的連結多肯定會影響網速,測試了好多次也確是如此。
- 2 、不美觀,分享按鈕外掛的樣式不能網站本身的設計很好的融合在一起。
- 3 、能用程式碼實現的功能就用程式碼,儘量減少外掛的使用。
替換分享連結中的標題與地址:
自定義分享按鈕,其實是很簡單,首頁我們需要獲取社交網站分享的連結地址,而這個不用我們操心,可以找百度分享、 JiaThis 等強大的分享按鈕。在任何有百度分享或 JiaThis 分享按鈕的網站中點選社交分享按鈕都會彈出一個分享頁面,網址就是我們需要的。
一般分享連結獲取的都是當前頁面的標題和地址,所以我們只需把分享連結中的標題與地址替換為 WordPress 的函式:
把分享連結中帶有&t=、&title=等其它標題樣式後面的標題替換為下面的程式碼:
把分享連結中帶有?url=、?link=等其它連結樣式後面的地址替換為下面的程式碼:
- <?php the_permalink(); ?>
因為分享連結中的標題與地址基本都是一大串字元,所以很難區分哪些才是標題,這裡有個簡單的方法,標題為例:
&title=%E5%88%86%E4%BA%AB%E6%8C%89%E9%92%AE&,在 「&title=」 後面與下一個 「&」 前面之間字元就是標題了,地址也是這樣。
新增分享連結按鈕:
下面的程式碼為分享的連結地址,一些程式碼是網上有就沒有重新編輯,把不需要的刪除,需要的一些分享按鈕筆者重新編輯新增了進來。程式碼中的 「社交圖示連結地址」 替換為你自己的圖示連結地址,新增到 single.php 檔案的相關位置:
- <!--筆者自定義分享按鈕-->
- <div class="share"><h3> 分享到:</h3>
- <a target="_blank" rel="nofollow" href="http://twitter.com/home/?status=<?php the_title(''); ?>:<?php the_permalink(); ?>" class="twitter-share" title="Twitter"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>&t=<?php the_title(''); ?>" class="facebook-share" title="Facebook"><img src="社交圖示連結地址" /></a>
- <a target="_blank" rel="nofollow" href="http://www.douban.com/recommend/?url=<?php the_permalink(); ?>&title=<?php the_title(''); ?>" class="douban-share" title="豆瓣"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://www.diandian.com/share?lo=<?php the_permalink(); ?>&ti=<?php the_title(''); ?>&type=link" class="diandian-share" title="點點"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://t.sohu.com/third/post.jsp?&url=<?php the_permalink(); ?>&title=<?php the_title(''); ?>&content=UTF-8" class="sohu-share" title="搜狐微博"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://t.163.com/article/user/checkLogin.do?link=<?php the_permalink(); ?>&source=yfdxs.com&info=<?php the_title(''); ?> <?php the_permalink(); ?>" class="netease-share" title="網易微博"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?&url=<?php%20the_permalink();%20?>&title=<?php%20the_title('');%20?>" class="sina-share" title="新浪微博"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://v.t.qq.com/share/share.php?title=<?php%20the_title('');%20?>&url=<?php%20the_permalink();%20?>&site=https://yfdxs.com/" class="tencent-share" title="騰訊微博"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://www.kaixin001.com/rest/records.php?url=<?php the_permalink(); ?>&style=11&content=<?php the_title(''); ?>&stime=&sig=" class="kaixin-share" title="開心網"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=<?php the_permalink(); ?>&title=<?php the_title(''); ?>&desc=&summary=&site=" class="qq-share" title="QQ 空間"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://share.renren.com/share/buttonshare?link=<?php the_permalink(); ?>&title=<?php the_title(''); ?>" class="renren-share" title="人人網"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://shuqian.qq.com/post?from=3&title=<?php the_title(''); ?>&uri=<?php the_permalink(); ?>" class="qqsq-share" title="QQ 書籤"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://cang.baidu.com/do/add?iu=<?php the_permalink(); ?>&it=<?php the_title(''); ?>&linkid=hjm6y313aqz" class="baidu-share" title="百度雲收藏"><img src="社交圖示連結地址"></a>
- <a target="_blank" rel="nofollow" href="http://feed.feedsky.com/salonglong" class="rss-share" title="訂閱我們"><img src="社交圖示連結地址"></a>
- </div>
或者也可以新一個 php 檔案 (custom_share.php),方便以後重複利用,把上面的程式碼新增到此檔案中,再用下面的程式碼把 custom_share.php 包括進來:
- <!-- 分享 -->
- <?php include('custom_share.php'); ?>
- <!-- 分享 end-->
新增分享按鈕樣式:
分享按鈕的樣式,複製到主題的樣式檔案就 OK:
- .share{
- background: #f8f8f8;
- overflow: hidden;
- height: 50px;
- border: 1px solid #ddd;
- border-radius: 5px;
- margin: 12px 0;
- }
- .user_avatar{
- background: #f8f8f8;
- border: 1px solid #ddd;
- border-radius: 4px 4px 0 0;
- margin-bottom: 12px;
- }
- .user_avatar img{
- margin: 8px 6px 0 8px;
- }
- .share h3{
- font-size: 14px;
- float: left;
- background: url(images/share.png) #3275a8 no-repeat;
- height: 50px;
- width: 123px;
- text-indent: -999px;
- }
- .share img{
- padding: 0;
- border: none;
- margin: 8px 1px;
- }
- .share h3,.share img{
- background-color: #dedede;
- }
- .share img:hover,.share h3:hover{
- background-color: #1e8dcc;
- }