Tag Archives: wordpress

How to transfer WordPress to Linode

This post will be put here as a backup, in case the other days I forget how to deal with such problem.


What I got is the first thing I should state here. The answer is a complete backups of the previous wordpress fold and a .sql database file. O.K, let’s begin.

Step 1, go to the name server to point the domain name to my Linode IP address.

Step 2, configure name-based virtual hosts. Create a file in the /etc/apache2/sites-available/ directory for each virtual host that you want to set up. Name each file with the domain for which you want to provide virtual hosting. See the following example configurations for the hypothetical “example.com” domain.

File:/etc/apache2/sites-available/example.com

<VirtualHost *:80>
     ServerAdmin webmaster@example.com
     ServerName example.com
     ServerAlias www.example.com
     DocumentRoot /srv/www/example.com/public_html/
     ErrorLog /srv/www/example.com/logs/error.log
     CustomLog /srv/www/example.com/logs/access.log combined
</VirtualHost>

After you’ve set up your virtual hosts, issue the following commands:

a2ensite example.com

This command symbolically links your virtual host file from sites-available to the sites-enabled directory. Finally, before you can access your sites you must reload Apache with the following command:

/etc/init.d/apache2 reload

Step 3,change the config file to suit your current environment, the config file locates /srv/www/ducklington.org/public_html/wp-config.php

Step 4, import the .sql file to your mysql database. Issue the following commands:

mysql -u username -p database_name < file.sql

The username and database_name should be change to the other names according to the wp-config.php file.


For further information, pleas check Manage Web Content with WordPress and LAMP Server on Ubuntu 10.04 (Lucid).

How to Embed Videoes in WordPress

As usual, this supposed to be an easy task, just copy the embed codes and all should work out fine. But in wordpress it didn’t… it turns out to be a bug or an error or anything you name it. Once you copy the embed codes into the HTML mode and switch to the normal edit mode, the codes simply disappeared. So it really a painful experience for me if I want embed any videos in my post, it seems that wordpress only accept certain kind of the embed codes. I resort to Google and found an easy way to fix the problem, though I don’t know exactly why it worked.

Find your theme’s function.php file. It usually located in your wordpress fold/themes/your theme/function.php or you can find it in your wordpress board, Appearance–Edit–function.php. Copy the following codes into this file, make sure to put  them in the right place, do not insert them to some functions.

function mytheme_tinymce_config( $init ) {
$valid_iframe = 'iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]';
if ( isset( $init['extended_valid_elements'] ) ) {
$init['extended_valid_elements'] .= ',' . $valid_iframe;
} else {
$init['extended_valid_elements'] = $valid_iframe;
}
return $init;
}
add_filter('tiny_mce_before_init', 'mytheme_tinymce_config');

Now, everything should be O.K.

几个关于WordPress里留言回复的邮件通知的问题

在WordPress里对留言的回复通过email告知对方是一种很好的交互方式,既让信息即使传达又加强用户间的互动。但这个功能我一直没能成功启用过,这个周末想到了这个问题于是折腾了一下。

首先找对方法,我从一开始就死盯着Comment Reply Notification这个插件,而我的主题用的是iNove 1.4.6,不管怎么样,看上去在这个主题下Comment Reply Notification这个插件无效。真是背,这个问题上浪费了n个小时。

然后我找了另一个插件Mail To Commenter,简单配置一下就能用了,但是这个插件要求严格的回复格式,要么是’@+user+blank‘,要么’@+user+:‘,但我测试下来用户体验并不太好,简单的说,当你点了“回复”之后,鼠标的定位不准,这样会造成格式错误,就无法通过邮件回复对方了。具体如下图:

Chrome:

From Drop Box

Firefox:

From Drop Box

IE下的情况和Firefox相同,所以我怀疑是代码本身有问题,看了一下还真是。点击“回复”之后触发一个js,该文件在我的博客空间是位于WordPress所在目录下…/wp-content/themes/inove/js/comment.js ,大家可以做个参考,应该也在差不多的位置。文件开头一看就看出了毛病:

function() {

function reply(authorId, commentId, commentBox) {
var author = MGJS.$(authorId).innerHTML;
var insertStr = ‘<a href=”#’ + commentId + ‘”>@n‘ + author.replace(/t|n|rn/g, “”) + ‘ ‘;

appendReply(insertStr, commentBox);
}

关键就是在代码的红字加粗部分,在插入’@+user+blank’后又换行一次,删除后Firefox和IE下点击“回复”,鼠标就定位在了’@+user+blank’之后,功能一切正常。但Chrome下无论我怎么改,鼠标始终定位在最开始,浑然不理代码。我也不懂什么原因,想想难道是因为Chrome解释js和别人不一样?有牛人能指正就不生感激了。

总得来说这样也就基本够用了,但肯定也不完善,把格式钉死成’@+user+blank’或者’@+user+:’ 当然不好,有人就是喜欢@user后打回车怎么办呢?不过我对php和js都不精通,只能暂时维持这个样子了。

接下来又发生胸闷的事,测试时,有留言被回复确实是会给被回复者发信,但邮件打头是(Unknown sender) ,这当然也是个不能接受的结果。查了一下碰到的人不多,本来想通过代码解决,mail函数也找不到,放弃了。根据这篇文章,下载了wp mail from解决。测试一下也成功了,至此终于马马虎虎地搞定了留言回复的邮件通知功能,虽然写下来好像没什么实质内容,但其实经历了无数试错,太痛苦了。。。而且一个问题的解决伴随的是无数新问题的产生,我发现我代码一长就看不懂,个人域名邮箱也完全不会配,WordPress果然是个催人不断折腾的好工具啊,下次有心得了再来写。

How to Delete WordPress Post Revisions

Just take a note, maybe I will use it someday. My memeries do not always serve me, tha’s so sad, -_-!!

As we all know WordPress saves your drafts automatically, that leaves a lot of revisions as backups on the server. It’s good, who wouldn’t  piss off if he typed for a long time and encountered some accidents like computer shut down for no reason. But on the other hand, when my articles posted, in most of the cases, I don’t need these revisions any more. Leaves them on the server as redundancy is useless and I guess they are adverse to the server’s performance. O.K., then things get really simple: KILL THEM ALL!

Try to access your WordPress database through some tools like phpMyAdmin(that’s the only tool I familiar with…), follow the steps below:

  1. Your database
  2. SQL
  3. type the following codes
    DELETE FROM wp_posts WHERE post_type = "revision";
  4. then press the button “Go”

Job Done.

WordPress升级到2.9后的一个问题

WordPress升级到2.9后莫名其妙地发现首页google reader shared items显示不正常,而后台控制板里也出现相同问题,都出现了如下的错误提示:

Warning: curl_setopt() [function.curl-setopt]: CURLPROTO_FILE cannot be activated when in safe_mode or an open_basedir is set in …

当时立马去google,发现很多人在报同样的问题但没什么解决方案,有的说是插件问题,停用再重启就好了,我也没这个精力去搞,首页停了google reader shared items的插件就没管了,想想等这官方的升级就应该可以解决了。今天又查查 了,官方好像依然没啥反应,但wordpress论坛又有大神出没,感谢eric.fournier提供的解决方案(具体参考这里,eric.fournier大神在13楼):
编辑文件 /wp-includes/http.php 找到第1300行,将

if ( defined( 'CURLOPT_TIMEOUT_MS' ) ) {
$timeout_ms = (int) ceil( 1000 * $r['timeout'] );
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT_MS, $timeout_ms );
curl_setopt( $handle, CURLOPT_TIMEOUT_MS, $timeout_ms );
} else {
$timeout = (int) ceil( $r['timeout'] );
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout );
}

替换为

if ( defined( 'CURLOPT_TIMEOUT_MS' ) ) {
// EDF - The option doesn't work with safe mode or when open_basedir is set. More
// research is probably necessary however this seems to fix the problems I was
// seeing in the "WordPress Development Blog" section of the Dashboard.
if ( !ini_get('safe_mode') && !ini_get('open_basedir') ) {
$timeout_ms = (int) ceil( 1000 * $r['timeout'] );
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT_MS, $timeout_ms );
curl_setopt( $handle, CURLOPT_TIMEOUT_MS, $timeout_ms );
}
} else {
$timeout = (int) ceil( $r['timeout'] );
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout );
}

O.K.,圆满解决。


update: 插件(Recommended Reading: Google Reader Shared)依然有问题,每次配置完以后是好的,首页一刷新,设置就丢了,比较奇怪。看了看官方论坛,放出了wordpress 2.9 beta1,装上以后对我的问题仍然没有解决。期待后续的正式版能解决。

关于Godaddy上架设WordPress那点事

图床在picasa,不能翻墙的朋友就掠过,略过吧。

遭遇三个问题:

  1. 问题描述:遭遇error,名为“Cannot modify header information…”。
    解决办法:将wp-config.php从主机上下载下来,用记事本等文本编辑器打开,再另存一遍,注意编码用ANSI
  2. 问题描述:Godaddy上架设Wordpress,那么wp-config.php里的MySQL主机名可就不是”localhost”了。(我梦游的主机上就是localhost,不知道是哪个主机比较另类。。?)那么MySQL主机名在哪里呢?
    解决办法:说大不清楚,还是看图说话吧。
  3. From Drop
    From Drop Box
    From Drop Box
    From Drop Box
    From Drop Box
    From Drop Box
    From Drop Box
  4. 问题描述:关于域名重定位,比如希望打开http://xxx.net自动转到http://xxx.net/blog
    解决办法:暂无。指标不治本的方法,是在http://xxx.net的首页里添加一句”<meta http-equiv=”refresh” content=”0.1;url=http://xxx.net/blog”>“,但这样访问者仍能看到http://xxx.net的预设页面,不是很爽。求解!