Moke|墨客

 找回密码
 立即注册
搜索
查看: 10212|回复: 0

Wordpress或discuz安装异次元分享工具条

[复制链接]

3636

主题

0

回帖

3681

积分

超级版主

Rank: 8Rank: 8

积分
3681
发表于 2016-5-9 15:33:30 | 显示全部楼层 |阅读模式



                异次元单篇文章顶部的分享工具条做的很美观,集成了新浪微博、腾讯微博、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> 前面,添加下面的代码:
            12                        <!--只在文章页加载js,以免IE在其他页面找不到对应的ID报错--><?php if ( is_single()){ ?><linkrel=&quot;stylesheet&quot;type=&quot;text/css&quot;href=&quot;<?php bloginfo('template_url'); ?>/share/share.css&quot; /><scripttype=&quot;text/javascript&quot;src=&quot;<?php bloginfo('template_url'); ?>/share/share_roll.js&quot;></script><?php } ?>            

4.打开 single.php ,在你需要显示工具条的位置添加下面的代码:
            1                        <?phpinclude(TEMPLATEPATH .'/share/share.php');?>            

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

贴出工具包里的代码share.php
            123456789101112                        <divid=&quot;share_toolbar_wrapper&quot;style=&quot;position: static; top: auto; z-index: 9999;&quot;><divid=&quot;share_toolbar&quot;><divclass=&quot;stb_group&quot;id=&quot;stb_article_view&quot;title=&quot;本文围观次数&quot;><spanid=&quot;stb_article_view_icon&quot;></span><spanid=&quot;stb_view_count&quot;><?php post_views(' ', ''); ?></span></div><divclass=&quot;stb_divide&quot;></div><divdata=&quot;{'url':'<?php the_permalink()?>'}&quot; class=&quot;bdshare_t bds_tools get-codes-bdshare stb_group stb_share_buttons&quot; id=&quot;bdshare&quot;>                        <ahref=&quot;javascript:void(0);&quot;id=&quot;stb_btn_weibo&quot;class=&quot;bds_tsina&quot;title=&quot;分享到新浪微博&quot;></a><ahref=&quot;javascript:void(0);&quot;id=&quot;stb_btn_tqq&quot;class=&quot;bds_tqq&quot;title=&quot;分享到腾讯微博&quot;></a><ahref=&quot;javascript:void(0);&quot;id=&quot;stb_btn_qzone_small&quot;class=&quot;bds_qzone&quot;title=&quot;分享到QQ空间&quot;></a><ahref=&quot;javascript:void(0);&quot;id=&quot;stb_btn_renren_small&quot;class=&quot;bds_renren&quot;title=&quot;分享到人人网&quot;></a><spanid=&quot;stb_btn_more&quot;class=&quot;bds_more&quot;><spanid=&quot;stb_sbtn_more_icon&quot;></span></span><ahref=&quot;javascript:void(0);&quot;class=&quot;shareCount&quot;></a></div><!--修改下一行的百度分享ID--><scripttype=&quot;text/javascript&quot;id=&quot;bdshare_js&quot;data=&quot;type=button&uid=12345&quot; ></script><scripttype=&quot;text/javascript&quot;id=&quot;bdshell_js&quot;></script><scripttype=&quot;text/javascript&quot;>                        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);                </script><divclass=&quot;stb_divide&quot;></div><divclass=&quot;stb_share_buttons stb_group&quot;><!-- 前一篇 --><?php $prev_post = get_previous_post(); if ($prev_post){ ?><aid=&quot;stb_btn_prev&quot;href=&quot;<?php echo get_permalink( $prev_post->ID ); ?>&quot; title=&quot;<?php echo '上一篇: ' ?><?php echo get_the_title( $prev_post->ID ); ?>&quot;></a><?php } else { ?><aid=&quot;stb_btn_prev&quot;href=&quot;&quot;title=&quot;<?php echo '当前为最早发布的文章,木有更早的啦!' ?>&quot;></a><?php } ?><!-- 下一篇 --><?php $next_post = get_next_post(); if ($next_post){ ?><aid=&quot;stb_btn_next&quot;href=&quot;<?php echo get_permalink( $next_post->ID ); ?>&quot; title=&quot;<?php echo '下一篇: ' ?><?php echo get_the_title( $next_post->ID ); ?>&quot;></a><?php } else { ?><aid=&quot;stb_btn_next&quot;href=&quot;&quot;title=&quot;<?php echo '当前为最新发布的文章,看看其他文章吧,同样精彩哦!' ?>&quot;></a><?php } ?></div><divclass=&quot;stb_group_right&quot;><divclass=&quot;stb_like_btn&quot;id=&quot;alipay_btn&quot;><!--修改下一行的链接地址为你的支付宝收款页面--><ahref=&quot;https://me.alipay.com/54321&quot;target=&quot;_blank&quot;title=&quot;捐助作者,与您共勉&quot;>.</a></div><divclass=&quot;bdlikebutton stb_like_btn bdlikebutton-blue bdlikebutton-small bdlikebutton-small-blue&quot;><divclass=&quot;bdlikebutton-inner&quot;><spanclass=&quot;bdlikebutton-add&quot;></span><divclass=&quot;bdlikebutton&quot;></div><divclass=&quot;bdlikebutton-count&quot;><!-- 处理百度like按钮点击和like数量 --><scriptid=&quot;bdlike_shell&quot;type=&quot;text/javascript&quot;></script><scripttype=&quot;text/javascript&quot;>                                                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();                                                </script></div></div></div></div></div></div>            

share.css
            1                        /分工具条*/#share_toolbar{background:nonerepeatscroll00#FCFCFC;border:1pxsolid#DDDDDD;border-radius:5px5px5px5px;height:33px;line-height:33px;width:auto;_display:none;}#share_toolbar_wrapper{background:nonerepeatscroll00#FFFFFF;padding-top:8px;}#stb_article_view{width:auto;+max-width:35px;}#stb_article_view#stb_article_view_icon{background:url(share.png)no-repeatscroll00transparent;display:block;height:14px;margin:3pxauto1px;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:05px;}.stb_group,.stb_divide{display:block;float:left;}.stb_divide{background:url(share.png)no-repeatscroll1px-19pxtransparent;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:nonerepeatscroll00#FCFCFC;border-color:-moz-use-text-color #DDDDDD#DDDDDD;border-image:none;border-right:1pxsolid#DDDDDD;border-style:nonesolidsolid;border-width:01px1px;display:none;padding:10px;position:absolute;top:34px;}.stb_share_buttons a{background:url(share.png)repeatscroll00transparent !important;display:block;float:left;height:25px !important;margin:4px005px;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)repeatscroll00transparent;display:block;float:left;height:16px;margin:1px003px;text-indent:-99999px;width:16px;}.stb_share_buttons_small a:hover{margin-top:0;}#stb_btn_more{background:nonerepeatscroll00transparent !important;display:block;float:left;height:33px;margin:0003px;padding:0;width:25px;}#stb_sbtn_more_icon{background-position:-20px0 !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:4px5px00;}#stb_like_gplus{margin-right:-20px;margin-top:7px;}#alipay_btn a{float:left;padding:0;width:107px;background:url(share.png)0-165pxno-repeat;color:#CBCBCD}#alipay_btn a:hover{margin-top:-1px;}.bdlikebutton{float:right;margin:4px5px00;}.stb_share_buttons.shareCount{width:1px;}#bdshare.shareCount{background:nonerepeatscroll0centertransparent;color:#5895BE;margin-top:8px;text-indent:0;}#share_toolbar#bdshare.shareCount:hover{margin-top:8px !important;}#bdshare{margin-right:5px;}            

            12345678                        /* author:eliteYangwebsite:http://www.zhangchenghui.com  desc:baidu share tool bardate:2013/05/07Desc:百度分享工具条滚动后修改CSS stylelicense:请尊重原创者,允许转载和修改,但需要保留链接,如有疑问,请至 黑苹果博客(www.zhangchenghui.com) 交流讨论 */var IO=document.getElementById('share_toolbar_wrapper'),Y=IO,H=0,IE6;IE6=window.ActiveXObject&&!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>H&&IO.fix||s<=H&&!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){};//]]>            

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

下面是安装过程中可能遇到的问题以及解决方法,希望对大家有用。
1、访问统计
必须安装WP-PostViews插件或者WP-PostViews Plus插件,我使用的是后者。  postview参数调用问题好像很多人都遇到,在share.php第五行<?php post_views(&lsquo; &lsquo;, &rdquo;);  ?>替换为<?php if(function_exists(&lsquo;the_views&rsquo;)) {the_views();}  ?>即可解决,很多主题中并没有将postviews参数定义进去,所以很多同学出现无法显示的问题。代码这样写也更加严谨一些,不会导致页面无法 显示。
2、宽度为690
如果不是这个宽度需要调整按钮的样式和多少来满足你主题的需要,我在使用中由于主题宽度不够就调整了几个按钮,但是发现有点小瑕疵,就是在跟随滚动时显示的宽度会缩小,css定义的宽度都是width: auto,将其定义为固定值就可解决这个问题。
3、跟随滚动
如果无法跟随滚动,那说明在js调用时于你使用的主题有冲突,请讲js调用的那段代码放到foot.php或者页面的结尾所有js后面,但要保证在</body>之前。我的做法是将
<?php if ( is_single() ) { ?>
<link rel=&rdquo;stylesheet&rdquo; type=&rdquo;text/css&rdquo; href=&rdquo;<?php bloginfo(&lsquo;template_url&rsquo;); ?>/share/share.css&rdquo; />
<?php } ?>
放在</head>前面,而将
<script type=&rdquo;text/javascript&rdquo; src=&rdquo;<?php bloginfo(&lsquo;template_url&rsquo;); ?>/share/share_roll.js&rdquo;></script>
放在foot.php文件的</body>之前。
此为wordpress博客添加异次元分享工具条的方法,至于discuz的论坛,由于篇幅限制粗略概括如下:

在模板文件 header.htm 里面的<head></head>之间添加  share.css 样式链接(每个使用的模板不同,请自行注意!)
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;{$_G[setting][jspath]}share/share.css&quot; />
然后找到footer.htm 在</body> 里面添加
<script type=&quot;text/javascript&quot; src=&quot;{$_G[setting][jspath]}share/share_roll.js&quot;></script>
在  viewthread_node.htm里面添加下面代码,具体位置可参考下面这个文件:viewthread_node.rar
<div id=&quot;share_toolbar_wrapper&quot; style=&quot;position: static; top: auto; z-index: 9999;width:660px &quot;>
<div id=&quot;share_toolbar&quot;>
<div class=&quot;stb_group&quot; id=&quot;stb_article_view&quot; title=&quot;本文围观次数&quot;>
<span id=&quot;stb_article_view_icon&quot;></span>
<span id=&quot;stb_view_count&quot;> $_G[forum_thread][views] </span>
</div>
<div class=&quot;stb_divide&quot;></div>
<div  data=&quot;{'url':'http://www.ouukuu.com/forum.php?mod=viewthread&tid=$_G[tid]'}&quot;  class=&quot;bdshare_t bds_tools get-codes-bdshare stb_group  stb_share_buttons&quot; id=&quot;bdshare&quot;>
<a href=&quot;javascript:void(0);&quot; id=&quot;stb_btn_weibo&quot; class=&quot;bds_tsina&quot; title=&quot;分享到新浪微博&quot;></a>
<a href=&quot;javascript:void(0);&quot; id=&quot;stb_btn_tqq&quot; class=&quot;bds_tqq&quot; title=&quot;分享到腾讯微博&quot;></a>
<a href=&quot;javascript:void(0);&quot; id=&quot;stb_btn_qzone_small&quot; class=&quot;bds_qzone&quot; title=&quot;分享到QQ空间&quot;></a>
<a href=&quot;javascript:void(0);&quot; id=&quot;stb_btn_renren_small&quot; class=&quot;bds_renren&quot; title=&quot;分享到人人网&quot;></a>
<span id=&quot;stb_btn_more&quot; class=&quot;bds_more&quot;><span id=&quot;stb_sbtn_more_icon&quot;></span></span>
<a href=&quot;javascript:void(0);&quot; class=&quot;shareCount&quot;></a>
</div>
<!--修改下一行的百度分享ID-->
<script type=&quot;text/javascript&quot; id=&quot;bdshare_js&quot; data=&quot;type=button&uid=12345&quot; ></script>
<script type=&quot;text/javascript&quot; id=&quot;bdshell_js&quot;></script>
<script type=&quot;text/javascript&quot;>
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);
</script>
<div class=&quot;stb_divide&quot;></div>
<div class=&quot;stb_share_buttons stb_group&quot;>
<!-- 前一篇 -->
<a id=&quot;stb_btn_prev&quot; href=&quot;forum.php?mod=redirect&goto=nextoldset&tid=$_G[tid]&quot; title=&quot;/&quot;></a>
<!-- 下一篇 -->
<a id=&quot;stb_btn_next&quot; href=&quot;forum.php?mod=redirect&goto=nextnewset&tid=$_G[tid]&quot; title=&quot;/&quot;></a>
</div>
<div class=&quot;stb_group_right&quot;>
<div class=&quot;stb_like_btn&quot; id=&quot;alipay_btn&quot;>
<!--修改下一行的链接地址为你的支付宝收款页面-->
<a href=&quot;http://me.alipay.com/mayun&quot; target=&quot;_blank&quot; title=&quot;捐助作者,与您共勉&quot;>.</a>
</div>
<div class=&quot;bdlikebutton stb_like_btn bdlikebutton-blue bdlikebutton-small bdlikebutton-small-blue&quot;>
<div class=&quot;bdlikebutton-inner&quot;>
<span class=&quot;bdlikebutton-add&quot;></span>
<div class=&quot;bdlikebutton&quot;></div>
<div class=&quot;bdlikebutton-count&quot;>
<!-- 处理百度like按钮点击和like数量 -->
<script id=&quot;bdlike_shell&quot; type=&quot;text/javascript&quot;></script>
<script type=&quot;text/javascript&quot;>
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();
</script>
</div>
</div>
</div>
</div>
</div>
</div>
解压share出来后 一致放到根目录的/static/js/ 。大功告成,赶紧测试你的简单美观又实用的集分享与捐赠的异次元工具条吧!
原文地址:http://www.zhangchenghui.com/apple/1848.html,转载请注明!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

 

 

快速回复 返回顶部 返回列表