异次元单篇文章顶部的分享工具条做的很美观,集成了新浪微博、腾讯微博、QQ空间、人人网等分享按钮,页面浏览数以及支付宝捐赠等功能。可惜的是没有分享出来,黑苹果博客分享高仿版,具体方法:

基于 eliteYang 的 Version 0.5 进行修改

1.修改“上一篇”和“下一篇”的调用顺序:我的理解是“上一篇”应该是 get_previous_post(),“下一篇”是 get_next_post()

2. 添加一个支付宝捐助按钮

3.简单精简和修改CSS和share.php代码

WordPress主题集成百度分享工具条

1.下载share工具包,解压出来。修改里面的 share.php 的 17、40、53 行(内有提示)。

2.把 share文件夹(含里面的文件)一起复制到 现用主题的根目录

3.在主题的 header.php 的</head> 前面 或者 footer.php 的 </body> 前面,添加下面的代码:

1
2
<!--只在文章页加载js,以免IE在其他页面找不到对应的ID报错--><?php if ( is_single()){ ?><linkrel="stylesheet"type="text/css"href="<?php bloginfo('template_url'); ?>/share/share.css" />
<scripttype="text/javascript"src="<?php bloginfo('template_url'); ?>/share/share_roll.js"></script><?php } ?>

4.打开 single.php ,在你需要显示工具条的位置添加下面的代码:

1
<?phpinclude(TEMPLATEPATH .'/share/share.php');?>

到此,已经将工具条集成到你的主题啦。

工具条的所有代码

贴出工具包里的代码share.php

 

 
  
  1. <dividdivid="share_toolbar_wrapper"style="position: static; top: auto; z-index: 9999;"><dividdivid="share_toolbar"><divclassdivclass="stb_group"id="stb_article_view"title="本文围观次数"><spanidspanid="stb_article_view_icon"></span><spanidspanid="stb_view_count"><?php post_views(' ', ''); ?></span></div><divclassdivclass="stb_divide"></div><divdatadivdata="{'url':'<?php the_permalink()?>'}" class="bdshare_t bds_tools get-codes-bdshare stb_group stb_share_buttons" id="bdshare"> 
  2.             <ahrefahref="vo< /span>id(0);"id="stb_btn_weibo"class="bds_tsina"title="分享到新浪微博"></a><ahrefahref="vo< /span>id(0);"id="stb_btn_tqq"class="bds_tqq"title="分享到腾讯微博"></a><ahrefahref="vo< /span>id(0);"id="stb_btn_qzone_small"class="bds_qzone"title="分享到QQ空间"></a><ahrefahref="vo< /span>id(0);"id="stb_btn_renren_small"class="bds_renren"title="分享到人人网"></a><spanidspanid="stb_btn_more"class="bds_more"><spanidspanid="stb_sbtn_more_icon"></span></span><ahrefahref="void(0);"< /span>class="shareCount"></a></div><!--修改下一行的百度分享ID--><scripttypescripttype="text/javascript"id="bdshare_js"data="type=button&uid=12345" ></script><scripttypescripttype="text/javascript"id="bdshell_js"></script><scripttypescripttype="text/javascript"> 
  3.             document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000); 
  4.         </script><divclassdivclass="stb_divide"></div><divclassdivclass="stb_share_buttons stb_group"><!-- 前一篇 --><?php $prev_post = get_previous_post(); if ($prev_post){ ?><aidaid="stb_btn_prev"href="<?php echo get_permalink( $prev_post->ID ); ?>title="<?php echo '上一篇: ' ?><?php echo get_the_title( $prev_post->ID ); ?>"></a><?php } else { ?><aidaid="stb_btn_prev"href=""title="<?php echo '当前为最早发布的文章,木有更早的啦!' ?>"></a><?php } ?><!-- 下一篇 --><?php $next_post = get_next_post(); if ($next_post){ ?><aidaid="stb_btn_next"href="<?php echo get_permalink( $next_post->ID ); ?>title="<?php echo '下一篇: ' ?><?php echo get_the_title( $next_post->ID ); ?>"></a><?php } else { ?><aidaid="stb_btn_next"href=""title="<?php echo '当前为最新发布的文章,看看其他文章吧,同样精彩哦!' ?>"></a><?php } ?></div><divclassdivclass="stb_group_right"><divclassdivclass="stb_like_btn"id="alipay_btn"><!--修改下一行的链接地址为你的支付宝收款页面--><ahrefahref="https://me.alipay.com/54321"target="_blank"title="捐助作者,与您共勉">.</a></div><divclassdivclass="bdlikebutton stb_like_btn bdlikebutton-blue bdlikebutton-small bdlikebutton-small-blue"><divclassdivclass="bdlikebutton-inner"><spanclassspanclass="bdlikebutton-add"></span><divclassdivclass="bdlikebutton"></div><divclassdivclass="bdlikebutton-count"><!-- 处理百度like按钮点击和like数量 --><scriptidscriptid="bdlike_shell"type="text/javascript"></script><scripttypescripttype="text/javascript"> 
  5.                         var bdShare_config = { 
  6.                             "type":"small", 
  7.                             "color":"blue", 
  8.                             "uid":"12345",//修改为你自己的百度分享id 
  9.                             "likeText":"喜欢", 
  10.                             "likedText":"已赞过" 
  11.                         }; 
  12.                         document.getElementById("bdlike_shell").src="http://bdimg.share.baidu.com/static/js/like_shell.js?t=" + new Date().getHours();                      </script></div></div></div></div></div></div> 
 
  
  1. /* author:eliteYangwebsite:http://www.zhangchenghui.com  desc:baidu share tool bardate:2013/05/07Desc:百度分享工具条滚动后修改CSS stylelicense:请尊重原创者,允许转载和修改,但需要保留链接,如有疑问,请至 黑苹果博客(www.zhangchenghui.com) 交流讨论 */ 
  2. var IO=document.getElementById('share_toolbar_wrapper'),Y=IO,H=0,IE6; 
  3. IE6=window.ActiveXObject&&!window.XMLHttpRequest;while(Y){H+=Y.offsetTop;YY=Y.offsetParent};if(IE6)IO.style.cssText="position:absolute;top:this.fix?(document"< /span>+".documentElement.scrollTop-(this.javascript||"+H+")):0)"; 
  4.   
  5. window.onscroll=function (){var d=document,s=Math.max(d.documentElement.scrollTop,document.body.scrollTop);if(s>H&&IO.fix||s<=H&&!IO.fix)return;if(!IE6){IOIO.style.position=IO.fix?"":"fixed";IO.style.top="0px";}         
  6.     IO.fix=!IO.fix;}; 
  7.   
  8. try{document.execCommand("BackgroundImageCache",false,true)}catch(e){};//]]> 

整个文件包中有5个文件,share.css, share.php ,share.png, share_roll.js 。按照上面的方案安装如果顺利就会看到如下图的效果了。

下面是安装过程中可能遇到的问题以及解决方法,希望对大家有用。

1、访问统计

必须安装WP-PostViews插件或者WP-PostViews Plus插件,我使用的是后者。 postview参数调用问题好像很多人都遇到,在share.php第五行<?php post_views(‘ ‘, ”); ?>替换为<?php if(function_exists(‘the_views’)) {the_views();} ?>即可解决,很多主题中并没有将postviews参数定义进去,所以很多同学出现无法显示的问题。代码这样写也更加严谨一些,不会导致页面无法显示。

2、宽度为690

如果不是这个宽度需要调整按钮的样式和多少来满足你主题的需要,我在使用中由于主题宽度不够就调整了几个按钮,但是发现有点小瑕疵,就是在跟随滚动时显示的宽度会缩小,css定义的宽度都是width: auto,将其定义为固定值就可解决这个问题。

3、跟随滚动

如果无法跟随滚动,那说明在js调用时于你使用的主题有冲突,请讲js调用的那段代码放到foot.php或者页面的结尾所有js后面,但要保证在</body>之前。我的做法是将

<?php if ( is_single() ) { ?>

<link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(‘template_url’); ?>/share/share.css” />

<?php } ?>

放在</head>前面,而将

<script type=”text/javascript” src=”<?php bloginfo(‘template_url’); ?>/share/share_roll.js”></script>

放在foot.php文件的</body>之前。

此为wordpress博客添加异次元分享工具条的方法,至于discuz的论坛,由于篇幅限制想知道的话请到我的黑苹果博客查看,地址是:http://www.zhangchenghui.com/apple/1848.html