WordPress添加仿异次元百度分享工具条

自从 WordPress大学 更换主题以来,不少同学都问倡萌,文章页面的百度分享工具条是如何实现的。其实,我也是在eliteYang  分享仿异次元百度分享工具条 看到,然后修改集成到我自己的主题的,下面将按照我自己的集成方法来说一下,当然了,你也可以去按照刚提到的文章那样去弄。

wpdaxue.com-201301312

倡萌的修改

基于 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> 前面,添加下面的引用CSS和JS的代码:

&lt;!--只在文章页加载js,以免IE在其他页面找不到对应的ID报错--&gt;
&lt;?php if ( is_single() ) { ?&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;&lt;?php bloginfo('template_url'); ?&gt;/share/share.css&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;&lt;?php bloginfo('template_url'); ?&gt;/share/share_roll.js&quot;&gt;&lt;/script&gt;
&lt;?php } ?&gt;

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

&lt;?php include(TEMPLATEPATH . '/share/share.php'); ?&gt;

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

注:该工具条的浏览次数统计功能,是倡萌自己的主题专用的,方法见《WordPress非插件添加文章浏览次数统计功能》,如果你想要正常显示浏览次数,请按照那篇文章说的添加代码。

@手语视点 测试说,即使安装 WP-PostViews 插件,使用<?php if(function_exists(‘the_views’)) {the_views();} ?> 替代 <?php post_views(‘ ‘, ”); ?>,页面正常,但统计也不会正常工作。倡萌不知道什么原因导致的,也没时间测试,如果你们测试也一样不行,就使用刚才说的添加统计代码吧。

工具条的所有代码

贴出工具包里的代码,感兴趣的,可以先预览

share.php

&lt;div id=&quot;share_toolbar_wrapper&quot; style=&quot;position: static; top: auto; z-index: 9999;&quot;&gt;
	&lt;div id=&quot;share_toolbar&quot;&gt;
		&lt;div class=&quot;stb_group&quot; id=&quot;stb_article_view&quot; title=&quot;本文围观次数&quot;&gt;
			&lt;span id=&quot;stb_article_view_icon&quot;&gt;&lt;/span&gt;
			&lt;span id=&quot;stb_view_count&quot;&gt;&lt;?php post_views(' ', ''); ?&gt;&lt;/span&gt;
		&lt;/div&gt;
		&lt;div class=&quot;stb_divide&quot;&gt;&lt;/div&gt;
		&lt;div data=&quot;{'url':'&lt;?php the_permalink()?&gt;'}&quot; class=&quot;bdshare_t bds_tools get-codes-bdshare stb_group stb_share_buttons&quot; id=&quot;bdshare&quot;&gt;
			&lt;a href=&quot;javascript:void(0);&quot; id=&quot;stb_btn_weibo&quot; class=&quot;bds_tsina&quot; title=&quot;分享到新浪微博&quot;&gt;&lt;/a&gt;
			&lt;a href=&quot;javascript:void(0);&quot; id=&quot;stb_btn_tqq&quot; class=&quot;bds_tqq&quot; title=&quot;分享到腾讯微博&quot;&gt;&lt;/a&gt;
			&lt;a href=&quot;javascript:void(0);&quot; id=&quot;stb_btn_qzone_small&quot; class=&quot;bds_qzone&quot; title=&quot;分享到QQ空间&quot;&gt;&lt;/a&gt;
			&lt;a href=&quot;javascript:void(0);&quot; id=&quot;stb_btn_renren_small&quot; class=&quot;bds_renren&quot; title=&quot;分享到人人网&quot;&gt;&lt;/a&gt;
			&lt;span id=&quot;stb_btn_more&quot; class=&quot;bds_more&quot;&gt;&lt;span id=&quot;stb_sbtn_more_icon&quot;&gt;&lt;/span&gt;&lt;/span&gt;
			&lt;a href=&quot;javascript:void(0);&quot; class=&quot;shareCount&quot;&gt;&lt;/a&gt;
		&lt;/div&gt;
		&lt;!--修改下一行的百度分享ID--&gt;
		&lt;script type=&quot;text/javascript&quot; id=&quot;bdshare_js&quot; data=&quot;type=button&amp;uid=12345&quot; &gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot; id=&quot;bdshell_js&quot;&gt;&lt;/script&gt;
		&lt;script type=&quot;text/javascript&quot;&gt;
			document.getElementById(&quot;bdshell_js&quot;).src = &quot;http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=&quot; + Math.ceil(new Date()/3600000);
		&lt;/script&gt;
		&lt;div class=&quot;stb_divide&quot;&gt;&lt;/div&gt;
		&lt;div class=&quot;stb_share_buttons stb_group&quot;&gt;
			&lt;!-- 前一篇 --&gt;
			&lt;?php $prev_post = get_previous_post(); if ($prev_post){ ?&gt;
				&lt;a id=&quot;stb_btn_prev&quot; href=&quot;&lt;?php echo get_permalink( $prev_post-&gt;ID ); ?&gt;&quot; title=&quot;&lt;?php echo '上一篇: ' ?&gt;&lt;?php echo get_the_title( $prev_post-&gt;ID ); ?&gt;&quot;&gt;&lt;/a&gt;
			&lt;?php } else { ?&gt;
				&lt;a id=&quot;stb_btn_prev&quot; href=&quot;&quot; title=&quot;&lt;?php echo '当前为最早发布的文章,木有更早的啦!' ?&gt;&quot;&gt;&lt;/a&gt;
			&lt;?php } ?&gt;
			&lt;!-- 下一篇 --&gt;
			&lt;?php $next_post = get_next_post(); if ($next_post){ ?&gt;
				&lt;a id=&quot;stb_btn_next&quot; href=&quot;&lt;?php echo get_permalink( $next_post-&gt;ID ); ?&gt;&quot; title=&quot;&lt;?php echo '下一篇: ' ?&gt;&lt;?php echo get_the_title( $next_post-&gt;ID ); ?&gt;&quot;&gt;&lt;/a&gt;
			&lt;?php } else { ?&gt;
				&lt;a id=&quot;stb_btn_next&quot; href=&quot;&quot; title=&quot;&lt;?php echo '当前为最新发布的文章,看看其他文章吧,同样精彩哦!' ?&gt;&quot;&gt;&lt;/a&gt;
			&lt;?php } ?&gt;
		&lt;/div&gt;
		&lt;div class=&quot;stb_group_right&quot;&gt;
			&lt;div class=&quot;stb_like_btn&quot; id=&quot;alipay_btn&quot;&gt;
				&lt;!--修改下一行的链接地址为你的支付宝收款页面--&gt;
				&lt;a href=&quot;https://me.alipay.com/54321&quot; target=&quot;_blank&quot; title=&quot;捐助作者,与您共勉&quot;&gt;.&lt;/a&gt;
			&lt;/div&gt;
			&lt;div class=&quot;bdlikebutton stb_like_btn bdlikebutton-blue bdlikebutton-small bdlikebutton-small-blue&quot;&gt;
				&lt;div class=&quot;bdlikebutton-inner&quot;&gt;
					&lt;span class=&quot;bdlikebutton-add&quot;&gt;&lt;/span&gt;
					&lt;div class=&quot;bdlikebutton&quot;&gt;&lt;/div&gt;
					&lt;div class=&quot;bdlikebutton-count&quot;&gt;
						&lt;!-- 处理百度like按钮点击和like数量 --&gt;
						&lt;script id=&quot;bdlike_shell&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
						&lt;script type=&quot;text/javascript&quot;&gt;
						var bdShare_config = {
							&quot;type&quot;:&quot;small&quot;,
							&quot;color&quot;:&quot;blue&quot;,
							&quot;uid&quot;:&quot;12345&quot;,//修改为你自己的百度分享id
							&quot;likeText&quot;:&quot;喜欢&quot;,
							&quot;likedText&quot;:&quot;已赞过&quot;
						};
						document.getElementById(&quot;bdlike_shell&quot;).src=&quot;http://bdimg.share.baidu.com/static/js/like_shell.js?t=&quot; + new Date().getHours();
						&lt;/script&gt;
					&lt;/div&gt;
				&lt;/div&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;

share.css

/*分享工具条*/
#share_toolbar{background:none repeat scroll 0 0 #FCFCFC;border:1px solid #DDDDDD;border-radius:5px 5px 5px 5px;height:33px;line-height:33px;width:auto;_display:none;}
#share_toolbar_wrapper{background:none repeat scroll 0 0 #FFFFFF;padding-top:8px;}
#stb_article_view{width:auto;+max-width:35px;}
#stb_article_view #stb_article_view_icon{background:url(share.png) no-repeat scroll 0 0 transparent;display:block;height:14px;margin:3px auto 1px;width:18px;}
#stb_article_view span{color:#AAAAAA;display:block;font-family:&quot;Helvetica Neue&quot;,Helvetica,Arial,sans-serif;font-size:11px;text-align: center;line-height:12px;margin:0 5px;}
.stb_group,.stb_divide{display:block;float:left;}
.stb_divide{background:url(share.png) no-repeat scroll 1px -19px transparent;height:33px;width:9px;}
.stb_submenu_link{position:relative;}
.stb_submenu_box{-moz-border-bottom-colors:none;-moz-border-left-colors:none;-moz-border-right-colors:none;-moz-border-top-colors:none;background:none repeat scroll 0 0 #FCFCFC;border-color:-moz-use-text-color #DDDDDD #DDDDDD;border-image:none;border-right:1px solid #DDDDDD;border-style:none solid solid;border-width:0 1px 1px;display:none;padding:10px;position:absolute;top:34px;}
.stb_share_buttons a{background:url(share.png) repeat scroll 0 0 transparent !important;display:block;float:left;height:25px !important;margin:4px 0 0 5px;text-indent:-99999px;width:81px;}
#share_toolbar .stb_share_buttons a:hover{margin-top:3px !important;}
#stb_btn_weibo{background-position:0 -57px !important;padding:0;}
#stb_btn_weibo_small{background-position:-83px -57px !important;padding:0;width:27px;}
#stb_btn_tqq{background-position:0 -83px !important;padding:0;}
#stb_btn_tqq_small{background-position:-83px -83px !important;padding:0;width:27px;}
#stb_btn_qzone{background-position:0 -135px !important;padding:0;}
#stb_btn_qzone_small{background-position:-83px -135px !important;padding:0;width:27px;}
#stb_btn_renren{background-position:0 -109px !important;padding:0;}
#stb_btn_renren_small{background-position:-83px -109px !important;padding:0;width:27px;}
.stb_share_buttons_small{left:-30px;width:150px;}
.stb_share_buttons_small a,#stb_sbtn_more_icon{background:url(share.png) repeat scroll 0 0 transparent;display:block;float:left;height:16px;margin:1px 0 0 3px;text-indent:-99999px;width:16px;}
.stb_share_buttons_small a:hover{margin-top:0;}
#stb_btn_more{background:none repeat scroll 0 0 transparent !important;display:block;float:left;height:33px;margin:0 0 0 3px;padding:0;width:25px;}
#stb_sbtn_more_icon{background-position:-20px 0 !important;margin-top:9px;}
#stb_btn_prev,#stb_btn_next{background-position:-9px -24px !important;width:33px;}
#stb_btn_next{background-position:-42px -24px !important;margin-left:0;width:32px !important;}
.stb_group_right{float:right;height:33px;width:205px;overflow:hidden;}
.stb_like_btn{float:left;margin:4px 5px 0 0;}
#stb_like_gplus{margin-right:-20px;margin-top:7px;}
#alipay_btn a{float:left;padding:0;width:107px;background:url(share.png) 0 -165px no-repeat;color:#CBCBCD}
#alipay_btn a:hover{margin-top:-1px;}
.bdlikebutton{float:right;margin:4px 5px 0 0;}
.stb_share_buttons .shareCount{width:1px;}
#bdshare .shareCount{background:none repeat scroll 0 center transparent;color:#5895BE;margin-top:8px;text-indent:0;}
#share_toolbar #bdshare .shareCount:hover{margin-top:8px !important;}
#bdshare{margin-right:5px;}

share_roll.js

/*
 
	author	:	eliteYang
	website	:	http://www.cppfans.org
	desc	:	baidu share tool bar
	date	:	2012/10/20
	Desc	:	百度分享工具条滚动后修改CSS style
	license	:	请尊重原创者,允许转载和修改,但需要保留链接,谢谢合作,祝大家使用愉快,如有疑问,请至 C++爱好者博客(www.cppfans.org) 交流讨论
 
*/
var IO=document.getElementById('share_toolbar_wrapper'),Y=IO,H=0,IE6;
IE6=window.ActiveXObject&amp;&amp;!window.XMLHttpRequest;
while(Y){H+=Y.offsetTop;Y=Y.offsetParent};
if(IE6)
    IO.style.cssText=&quot;position:absolute;top:expression(this.fix?(document&quot;+
        &quot;.documentElement.scrollTop-(this.javascript||&quot;+H+&quot;)):0)&quot;;
 
window.onscroll=function (){
    var d=document,s=Math.max(d.documentElement.scrollTop,document.body.scrollTop);
    if(s&gt;H&amp;&amp;IO.fix||s&lt;=H&amp;&amp;!IO.fix)return;
    if(!IE6){IO.style.position=IO.fix?&quot;&quot;:&quot;fixed&quot;;IO.style.top=&quot;0px&quot;;}        
    IO.fix=!IO.fix;
};
 
try{document.execCommand(&quot;BackgroundImageCache&quot;,false,true)}catch(e){};
 //]]&gt;

来源:

https://www.wpdaxue.com/wordpress-add-baidu-share-tool.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33290.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?