其实这是别人在Wordpress.org.cn上提出来的问题,因为我也时不时弄下校内,所以就研究了下怎么实现。
首先,找到你所使用模板里的single.php,用文本编辑器打开(注意选择用UTF-8编码,某则会出现乱码)。
在适当位置添加一下代码:
<a href="http://share.xiaonei.com/share/buttonshare.do?link=<?php the_permalink() ?>&title=<?php the_title(); ?>"target="_blank">分享到校内</a>
解释:
http://share.xiaonei.com/share/buttonshare.do?link=
是校内提交分享地址的接口,等号后面的就是所需提交的地址;
<?php the_permalink() ?>
这个是WordPress提取当前页面url的函数;
<?php the_title(); ?>
这个是提取当前日志标题的函数。
这样,我们就像搭积木搬的搭出一段分享日志到校内的代码。
另外还有一种方法,根据校内提供给FireFox快速分享标签的代码,我们可以直接拿过来套用:
<a href="javascript:void((function(s,d,e){if(/xiaonei\.com/.test(d.location))return;var%20f='http://share.xiaonei.com/share/buttonshare.do?link=',u=d.location,l=d.title,p=[e(u),'&title=',e(l)].join('');function%20a(){if(!window.open([f,p].join(''),'xnshare',['toolbar=0,status=0,resizable=1,width=626,height=436,left=',(s.width-626)/2,',top=',(s.height-436)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent));">分享到校内</a>
对于这一串长的恶心的javascript代码,我也无能力详细解释了,反正用上去效果绝对不错。
对于代码添加位置的说明:
一般来说找到single.php里面的<div id="comments">,添加于这个之上;
如果你的single.php有<div id="copyright">,你可以直接添加在这里面;
如果没有,你可以先定义个<div id="share"> ,然后添加这里面添加上面所写的代码;
到这里,我们就可以以此类推的添加更多的分享网站:
以下代码收集于网络,未作有效性测试。
<a href="http://shuqian.qq.com/post?from=3&title=<?php the_title(); ?>&uri=<?php the_permalink() ?>" target="_blank">QQ书签</a>
<a href="http://cang.baidu.com/do/add?it=<?php the_title(); ?>&iu=<?php the_permalink() ?>" target="_blank">百度收藏</a>
<a href="http://del.icio.us/post?url=<?php the_permalink() ?>&title=<?php the_title(); ?>" target="_blank">Del.icio.us</a>
<a href="http://google.com/bookmarks/mark?op=edit&bkmk=<?php the_permalink() ?>&title=<?php the_title(); ?>" target="_blank">Google书签</a>
<a href="http://www.xianguo.com/service/submitfav/?link=<?php the_permalink() ?>&title=<?php the_title(); ?>" target="_blank">鲜果</a>
<a href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=<?php the_permalink() ?>&=<?php the_title(); ?>" target="_blank">yahoo收藏</a>
<a href="http://digg.com/submit?phase=2&url=<?php the_permalink() ?>&title=<?php the_title(); ?>" target="_blank">digg</a>
<a href="http://www.diglog.com/submit.aspx?title=<?php the_title(); ?>&url=<?php the_permalink() ?>">diglog</a>
当然,为了保持页面整洁,我们可以在主题样式中定义一下:
可根据自己喜好修改。
#share p {
border-bottom:1px solid #D2D2D2;
color:#717171;
font-size:12px;
line-height:25px;
margin-right:20px;
background:#99FF99;
}
由于各个模板的single.php不尽相同,所以我也无法提供确切的代码添加位置,要用的话务必先在本地环境中摸索测试下再上传。
不错啊,函数和CSS都提供了,顶一个
@万戈 谢谢万戈兄帮顶,话说我也是受到你“能不用插件实现的坚决不用插件”的理念才写出来的。
哈哈,是受我感化呀,谢谢谢谢
这个功能不错!
論壇是學習的好地方!
不错,学习一下
校内账号已注销
偶也注销了校内!呵呵
不用插件,方法很好~不过校内不好。
这个暑假没有网线,手机帮顶!
@卢松松 谢谢,我也是依葫芦画瓢写出来的。。
@willin 对,不过我在论坛上潜水占大多数时间。。
@qrpenp 谢谢!
@芒果 难道是现在流行注销校内帐号了。。。
@huaimao 难道是现在流行注销校内帐号了。。。
@阿修 原来是没网线了啊,我怎么说你那边老没更新,谢谢你用手机帮顶,这种精神必须赞扬。。
呵呵,正是我想要的
你这篇文章非常实用哦,我想在自己的博客上显示校内里的状态,你试过吗? 我看有人在博客里显示了twitter的相关信息,校内也应该可以,我看了一下api不是很明白,你知道如何实现吗?如果知道,麻烦回个email,谢谢
这个博主也强大