在使用WordPress过程中,有时为了方便阅读着分享到主流的社交网站或微薄,需要在文章旁边添加一些分享按钮。如下图,本文就介绍简单对WordPress做些简单修改来完成对分享的支持.
相关代码和图片打包下载:
修改步骤如下:
零 : 把下载好的images下面的图标文件上传到你的空间中。
一 :把写好的 shareto.php 上传到你的主题目录,然后把其中的图片的地址改为你自己上传的 如: /wp-content/themes/你的主题名字/ 下面:
<?php
//shareto.php
$permalink = urlencode(get_permalink($post->ID));
$title = urlencode($post->post_title);
$title = str_replace('+','%20',$title);
$sitename="cngump";
$domainurl="http://www.cngump.com/";
//把下面的图片url替换成自己的空间的url
?>
<h3>我要分享到:</h3>
<ul>
<li><a title="新浪微博" rel="nofollow" href="http://v.t.sina.com.cn/share/share.php?url=<?php echo $permalink; ?>&title=<?php echo $title; ?>&content=utf-8" target="_blank"><img title="新浪微博" src="http://www.cngump.com/images/bookmark/sina.png" alt="新浪微博" /></a></li>
<li><a title="腾讯微博" rel="nofollow" target="_blank" href="javascript:window.open('http://v.t.qq.com/share/share.php?title='+'<?php echo $title; ?>'+encodeURIComponent(document.title)+'&url='+encodeURIComponent('<?php echo $permalink; ?>')+'&jumpback=2&noui=1','favit','width=700,height=546,left=50,top=50,toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes');void(0)" >
<img title="腾讯微博" src="http://www.cngump.com/images/bookmark/tqq.png" alt="腾讯微博" />
</a></li>
<li><a title="网易微博" rel="nofollow" href="http://t.163.com/share/popup?sourceUrl=<?php echo $domainurl; ?>&source=<?php echo $sitename; ?>&title=<?php echo $title; ?>&link=%20<?php echo $permalink; ?>&content=utf-8" target="_blank"><img title="网易微博" src="http://www.cngump.com/images/bookmark/t163.png" alt="网易微博" /></a></li>
<li><a title="鲜果" rel="nofollow" href="http://www.xianguo.com/service/submitdigg/?link=<?php echo $permalink; ?>&title=<?php echo $title; ?>&content=utf-8" target="_blank"><img title="鲜果" src="http://www.cngump.com/images/bookmark/xianguo.png" alt="鲜果" /></a></li>
<li><a title="九点" rel="nofollow" href="http://www.douban.com/recommend/?url=<?php echo $permalink; ?>&title=<?php echo $title; ?>&n=1" target="_blank"><img title="九点" src="http://www.cngump.com/images/bookmark/douban9.png" alt="九点" /></a></li>
<li><a title="人人" rel="nofollow" href="http://share.renren.com/share/buttonshare.do?link=<?php echo $permalink; ?>&title=<?php echo $title; ?>" target="_blank"><img title="人人" src="http://www.cngump.com/images/bookmark/renren.png" alt="人人" /></a></li>
<li><a title="抽屉" rel="nofollow" href="http://dig.chouti.com/digg.action?newsURL=<?php echo $permalink; ?>&title=<?php echo $title; ?>&content=utf-8" target="_blank"><img title="抽屉" src="http://www.cngump.com/images/bookmark/chouti.png" alt="抽屉" /></a></li>
<li><a title="百度搜藏" rel="nofollow" href="http://cang.baidu.com/do/add?it=<?php echo $title; ?>&iu=<?php echo $permalink; ?>" target="_blank"><img title="百度搜藏" src="http://www.cngump.com/images/bookmark/baidu.png" alt="百度搜藏" /></a></li>
<li><a title="Follow5" rel="nofollow" href="http://www.follow5.com/f5/discuz/sharelogin.jsp?url=<?php echo $permalink; ?>&title=<?php echo $title; ?>&content=utf-8" target="_blank"><img title="Follow5" src="http://www.cngump.com/images/bookmark/f5.png" alt="Follow5" /></a></li>
<li><a title="Twitter" rel="nofollow" href="http://twitter.com/home?status=<?php echo $title; ?>%20-%20<?php echo $permalink; ?>" target="_blank"><img title="Twitter" src="http://www.cngump.com/images/bookmark/twitter.png" alt="Twitter" /></a></li>
<li><a title="Facebook" rel="nofollow" href="http://www.facebook.com/share.php?u=<?php echo $permalink; ?>&t=<?php echo $title; ?>" target="_blank"><img title="Facebook" src="http://www.cngump.com/images/bookmark/facebook.png" alt="Facebook" /></a></li>
</ul>
根据你的图片路径在文中修改相应的img的url即可
二. 修改你的主题样式文件,在style.css最后加上以下样式,如:/wp-content/themes/你的主题名字/sytle.css
/************************************************
* shareto *
************************************************/
#share {
-moz-border-radius:5px 5px 5px 5px;
-webkit-border-radius: 5px;
float:left;
}
#share li {
float:left;
margin:6px 0 0 5px;
padding:4px 0 4px 8px;
list-style-type:none;
background:none;
}
三. 修改单编日志页面的index.php(main index template),有的主题是single.php。把以下代码加到你想放的位置。
<div id="share"> <?php include(TEMPLATEPATH."/shareto.php");?> </div>
九. 刷新文章页面看看效果和测试。
#源代码
# url_blip_tv.py
import re
import urllib
__author__ = 'cngump'
#config
rss_url="http://pycon.blip.tv/rss" #rss feed list
html_file="pycon2011.html" #html file name
#parse
f = urllib.urlopen(rss_url)
content=f.read()
#regex PyCon2011's mp4
regex=r'http://blip.tv/file/get/Pycon\-PyCon2011(?P<name>.*?)\.mp4'
reobj=re.compile(regex)
html="<html><head><title>pycon2011</title></head><body>"
url_list=[]
for abc in reobj.finditer(content):
print abc.group()
url=abc.group()
if(url not in url_list):
url_list.append(url)
html=html+"<a href='{0}'>{0}</a><br>\n".format(url)
#write
html=html+"</body></html>"
html_file = open(html_file, 'w')
html_file.write(html);
Python源代码打包下载
url_blip_tv.py
linux或者mac用户使用命令批量下载:
wget –force-html -i pycon2011.html
widnows用户
用浏览器打开 pycon2011.html 文件,然后用迅雷批量下载。
2011.01.23在珠三角小沙龙做的一个主题,由于那天主题太多,到了最后还有很多主题都没有讲,本打算就我的主题放到下一期去讲,但是一想大家对Java兴趣也不高,就用最快的速度过一遍就OK了,后来只用了大约5分钟就讲完了。话题没有太多具体的例子,只是从大局介绍了一下,希望对小白能有所帮助。
随着Google Calendar已经可以看到2011年,但是对于一个中国人来讲,春节没有过,还不是新年。现在离春节还有10天左右,最近忙了很多事,然后做了一个艰难的决定,决定重开Blog,虽然重开,之前一切也没有迁移了,连名字也有原来的 老甘Blog 改为 老甘的可读区。 虽然本人不好写作,但是为了为以后的生活和技术多做一些记录,决定以后把blog继续写下去。
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
最近留言