Posted in wordpress on 12/05/2009 10:43 下午 by tunpishuang
wordpress的修订功能貌似过于专业了点,对于一般的blogger不实用,需要禁用掉,方法有总结一下。
-
第1种
- wp-config.php中加入代码
1
| define(’WP_POST_REVISIONS’, false); |
貌似不能完全关闭。
-
第2种
-
1 2
| 用mysql客户端中执行:
DELETE FROM wp_posts WHERE post_type = 'revision'; |
-
第3种
- 使用插件 No Revisions 或者 插件 Revision Control
Posted in wordpress on 11/18/2009 10:14 下午 by tunpishuang
wordpress中加入转载声明对于原创作者是很重要的。
因为主题的不同,可能具体修改代码的位置有所不同。以本博客的oriental主题为例。
打开主题目录的single.php,定位到23行:
23 24 25
| <div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div> |
在23行下面加入我们的转载声明,最终代码如下:
23 24 25 26 27 28 29 30
| <p>
本文链接:<a href="<?php the_permalink();?>" title="<?php the_permalink();?>"><?php single_post_title(); ?></a>
@ <a href="<?php bloginfo('siteurl'); ?>"><?php bloginfo('name'); ?></a> ,
作者:<?php the_author()?>
</p>
<div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div> |

done!
Posted in wordpress on 10/18/2009 03:51 下午 by tunpishuang

wordpress自带的搜索功能没有google强大,所以想把博客的搜索功能替换成google自定义搜索。翻了翻网上的资料,发现自定义搜索已经改版了,表面上看没有以前的功能强大,实则有被ajax google search api代替的趋势。
现在登录http://www.google.com/cse/?hl=zh-CN ,生成一个最简单的搜索框的代码如下:
1 2 3 4 5 6 7 8 9
| <!-- Google Custom Search Element -->
<div id="cse" style="width:100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1');
google.setOnLoadCallback(function(){
new google.search.CustomSearchControl('003302537028975418586:ymvle_l4feq').draw('cse');
}, true);
</script> |
搜索的结果是ajax无刷新取得的,但是,花了点时间读了google search api , 尝试在我的博客上使用。我用的主题是oriental,把搜索的结果用draw插入到id为contentinner的div中,但是样式完全惨目忍睹,暂时没有时间来分析原因,我猜想是因为oriental的css应用到了搜索结果上了。
只有采用老方法:
因为oriental的搜索框是在header.php中的,所以定位到header.php,把一下代码放在searchBar这个div中:
57 58 59 60 61 62 63 64 65 66 67 68
| <div id="searchBar">
<form action="http://www.google.com/cse" id="cse-search-box">
<div>
<input type="hidden" name="cx" value="003302537028975418586:ymvle_l4feq" />
<input type="hidden" name="cof" value="FORID:11" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="text" name="q" size="31" />
<input type="submit" name="sa" value="搜索" />
</div>
</form>
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=zh-Hans"></script>
</div> |
cx是自定义搜索的唯一id,需要一个google账户,在http://www.google.com/cse/?hl=zh-CN中新建,然后自动分配,全世界唯一。
基本上就这样:


Posted in google, wordpress on 10/17/2009 01:19 上午 by tunpishuang
上次的wordpress故障在解决的同时发现了一个惊天的秘密,俺的web根目录下的.htaccess被修改。
被修改成这样:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| # BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} (Googlebot|Slurp|msnbot)
RewriteRule ^ http://doormoney.us/ [R=301,L] |
难怪google仅仅收录了本站4页,原来google,yahoo,msn的机器人都被301带到了一个叫doormoney.us的网站,估计是哪个sb插件修改的,要么就是被黑了?貌似是个白俄罗斯的网站。啥内容也没有。
删掉# BEGIN WordPress和# END WordPress之间以外所有内容,现在爬虫又开始在我的网站上抓取了。我艹,速度还真快啊,昨天晚上收录才4个,今天就23了。看来bot们被这该死的.htaccess规则给憋坏了。
Posted in wordpress on 10/16/2009 05:46 上午 by tunpishuang

事情大概发生在2009/10/12,昨天进了本站后台发现全部内容归0,如上图所示。把我吓了一跳。前台的东西完全可以正常访问。我比较怀疑是数据库的问题。试着自己解决,恢复数据到10月7号,问题照旧。本来还打算叫空间的管理员恢复全部内容到10.7,在恢复前的1分钟,它自己又正常了:

过了一会又“归0”了,相当的邪门 。
到wordpress.org.cn上发帖求助发现没有鸟我,鸟我的也说没有出现过这种情况,然后到wordpress官方论坛发贴,有人解答,方法是删除.htaccess,重新在permalink中自动生成,或者修复mysql所有表。但是貌似都不管用。
无奈之下求教了空间管理员-“黑山老妖”,把后台的密码给了他,结果他禁用了插件akismet一些恢复如初。后台的速度也比以前快了,看来akismet确实是罪魁祸首啊。我对黑山老妖表示万分的感谢,同时我也十分的纳闷akismet插件和这个概况的显示有好大的关系,具体的代码我就不深究了。总之,这确实很邪门。
Posted in wordpress on 08/23/2009 06:44 下午 by tunpishuang

wordpress程序的更新确实很快,有时候升级起来都觉得麻烦,担心出现兼容性的问题,记得最后一次升级是升级到2.7.1解决了一个WordPress2.7.1升级超时问题。
我的方法是:
首先一定要做好的工作就是备份,要是没有备份就升级,要是出了问题就完蛋了。我把备份的sql导入本地搭建的wordpress2.8.4,首先查看本地的wordpress升级后运行有没有问题。具体的做法是:
- 到cn.wordpress.com下载最新中文版的wordpress。
- 使用wordpress database backup插件导出sql
- 本地安装phpnow之类的amp套件,登录自带的phpmyadmin,然后建立一个数据库,比如叫做wordpress。
- 修改下载下来的wordpress2.8.4-zh_CN根目录下载wp-config-sample.php 改名为wp-config.php 然后打开wp-config.php添加上自己的数据库名,用户名和密码。
- 用ultrastudio打开sql文件,批量替换http://techguru.cn 为http://localhost/wordpress 保存
- 在phpmysql导入sql文件,打开http://localhost/wordpress/wp-admin/ 应该可以看到升级数据库结构的网页,点升级。
- 浏览网页是否正常,我浏览自己的主页正常,但是进入单个页面就自动转入主页,或者显示404错误,解决的方法是:打开apache2的配置文件httpd.conf 确认
- LoadModule rewrite_module modules/mod_rewrite.so 这句前面没有#符号,
<Directory />
Options FollowSymLinks
AllowOverride No //改为AllowOverride All
Order deny,allow //改为Order allow,deny
Deny from all //改为Allow from all
</Directory>
重启动apache2,再次浏览就没有问题了。
- 确认本地的没有问题后,在后台,禁用所有插件,使用wordpress默认主题,移除所有小工具。然后直接点“自动升级”,等待4-5分钟,升级完成了,然后进自己的页面看看有没有错误,将出错的插件禁用,然后升级插件或者琢磨其他的方法。
- 最后将自己的主题还原,小工具都添加上,搞定。
此文是2.8.4升级后的第一文,给我的感觉布局没有太大的变化,后台看稍加的清爽了一下,后台的配色我喜欢,估计是因为之前那个灰色有点审美疲劳了,其他的还在挖掘中。
Posted in wordpress on 04/01/2009 07:10 下午 by tunpishuang

改的原因主要是页面完全没有目录重要,页面直接拖到sidebar做个链接就可以了。
定位到主题目录下面的header.php
找到div是navlist的
1 2 3 4 5 6 7 8
| <div id="navcontainer">
<ul id="navlist">
<li id="first"><a href="#"> </a></li>
<li <?php if ($post->post_type != 'pages') echo " class=\"current_page_item\""; ?>><a href="<?php bloginfo('url'); ?>">Home</a></li>
<?php wp_list_pages('orderby=name&&title_li=&hide_empty=1'); ?>
</ul>
</div> |
把改为
wp_list_pages()是用来列页面的,wp_list_categories()是用来列目录的,参数有很多,最重要的还是orderby决定了列目录的顺序,title_li决定了是否需要标题,更多的参数参见“Template Tags/wp list categories Wordpress Codex”但是做导航是不需要这玩意的,效果如图:

Posted in wordpress on 02/13/2009 04:24 下午 by tunpishuang

WordPress2.7.1在
$response = wp_remote_get($url, array('timeout' => 3000));
把30000改成30000000000000,我想应该没问题了,结果升级成功,确实没问题:

Posted in wordpress on 02/10/2009 01:23 上午 by tunpishuang
默认情况下,Wordpress最新评论widgets的形式为:

也就是 >>comment_author 在 comment_post_ID 上的评论
我现在需要把评论者的站点链接和评论内容链接去掉,然后改成这样:
>>comment_author 说道:comment_content >>
(本文以WP2.7中本版为例)
先在网路上抓个Poedit下来,安装好,当然有Chinese Simplifed就再好不过了,编辑Wordpress目录下的\wp-content\languages\zh_CN.po
搜索“上的评论” 定位到第一个搜索到的“上的评论” ,可以发现是这样的:
原文:%1$s on %2$s
译文:%1$s 在 %2$s 上的评论
现在把译文改成这样:%1$s 说道: %2$s ,保存zh_CN.po
接下来用任意编辑器打开\wp-includes\comment-template.php,定位到132到150行:
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| /**
* Retrieve the html link to the url of the author of the current comment.
*
* @since 1.5.0
* @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
*
* @return string Comment Author name or HTML link for author's URL
*/
function get_comment_author_link() {
/** @todo Only call these functions when they are needed. Include in if... else blocks */
$url = get_comment_author_url();
$author = get_comment_author();
if ( empty( $url ) || 'http://' == $url )
$return = $author;
else
$return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
return apply_filters('get_comment_author_link', $return);
} |
以上代码是get_comment_author_link()的定义,当$url变量有值的时候,返回一个带链接的author,我不需要链接,所以改为:
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| /**
* Retrieve the html link to the url of the author of the current comment.
*
* @since 1.5.0
* @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
*
* @return string Comment Author name or HTML link for author's URL
*/
function get_comment_author_link() {
/** @todo Only call these functions when they are needed. Include in if... else blocks */
$url = get_comment_author_url();
$author = get_comment_author();
if ( empty( $url ) || 'http://' == $url )
$return = $author;
else
$return = "$author";
return apply_filters('get_comment_author_link', $return);
} |
接下来打开wp-includes\widgets.php 定位到1399到1402行:
1399 1400 1401 1402 1403
| <ul id="recentcomments"><?php
if ( $comments ) : foreach ( (array) $comments as $comment) :
echo '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_comment_link($comment->comment_ID) . '">' . <span style="text-decoration: underline;">get_the_title($comment->comment_post_ID)</span> . '</a>') . '</li>';
endforeach; endif;?>
</ul> |
下划线部分改为:$comment->comment_content ,保存。
好了,搞定,看下效果:

需要改代码,有点麻烦,不过生命就是在于折腾!
Posted in wordpress on 10/28/2008 08:40 下午 by tunpishuang
今天做了个关于俺们一个自考的HTML页面,因为表格多,所以没有作成page。就打算用page来链接过去,我用的方法是在改页面编辑器中打开“HTML源代码”,贴入:
<script type=”text/javascript”>
<!–
location=”http://techguru.cn/note/SEHE-roadmap.html“;
// –>
</script>
该用法页面跳转在加载header title等之前,所以有闪屏的感觉:P
就是用js跳转,我知道这方法很傻,很天真,不过对于我们这种不了解WP API函数的也差不多了。有时间定学习一下WP。
我希望这个页面可以鼓励我努力考试,不要沉迷网络~
在WP做之前有个全部用静态html写的类日记网页,俺称之为“手动勃”。
-
ps:第二天的《写作》考得一般,允许拿词典的我没有拿,是我没词典,图书馆星期五关门,班上都TM工科的谁有这玩意儿呢?我承认我装13了,不过是被动装13.