Sep 06
作者: 肖建彬 | 可以转载, 转载时务必以超链接形式标明文章原始出处和作者信息及版权声明
网址:http://www.xiaojb.com/archives/it/mt2wp-howto.shtml
网址:http://www.xiaojb.com/archives/it/mt2wp-howto.shtml
安装好wordpress后,需要将MovableType的数据导入其中,难题是保证每一篇博客的url不变,下边步骤就是我的做法。
- 修改MT的源码,导出备份
- 安装WP,并安装和启用插件Jerome’s Keywords
- 修改WP源码,使其支持Basename和Keywords的导入
- --- wordpress.org/wp-admin/import/mt.php 2006-05-19 14:22:55.000000000 +0800
- +++ wordpress/wp-admin/import/mt.php 2006-09-06 17:59:47.000000000 +0800
- @@ -179,6 +179,7 @@
- if ('' != trim($post)) {
- ++ $i;
- unset ($post_categories);
- + $post_name = '';
- // Take the pings out first
- preg_match("|(-----\n\nPING:.*)|s", $post, $pings);
- @@ -188,9 +189,14 @@
- preg_match("|(-----\nCOMMENT:.*)|s", $post, $comments);
- $post = preg_replace("|(-----\nCOMMENT:.*)|s", '', $post);
- - // We ignore the keywords
- + preg_match("|-----\nKEYWORDS:(.*)|s", $post, $keywords);
- + $post_keywords = $wpdb->escape(trim($keywords[1]));
- $post = preg_replace("|(-----\nKEYWORDS:.*)|s", '', $post);
- + preg_match("|-----\nBASENAME:(.*)|s", $post, $basename);
- + $post_name = $wpdb->escape(trim($basename[1]));
- + $post = preg_replace("|(-----\nBASENAME:.*)|s", '', $post);
- +
- // We want the excerpt
- preg_match("|-----\nEXCERPT:(.*)|s", $post, $excerpt);
- $post_excerpt = $wpdb->escape(trim($excerpt[1]));
- @@ -225,6 +231,12 @@
- case 'TITLE' :
- $post_title = $wpdb->escape($value);
- break;
- + case 'KEYWORDS' :
- + $post_keywords = $value;
- + break;
- + case 'BASENAME' :
- + $post_name = $wpdb->escape($value);
- + break;
- case 'STATUS' :
- // "publish" and "draft" enumeration items match up; no change required
- $post_status = $value;
- @@ -281,8 +293,14 @@
- $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor
- - $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
- + $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'post_name');
- $post_id = wp_insert_post($postdata);
- + if($post_keywords && $post_keywords!='-----') {
- + if(strstr($post_keywords,'-----')) {
- + $post_keywords = trim(str_replace('-----','',$post_keywords));
- + }
- + add_post_meta($post_id, 'keywords', $post_keywords);
- + }
- // Add categories.
- if (0 != count($post_categories)) {
- wp_create_categories($post_categories, $post_id);
- 修改永久连接(Permalink)选项
我的MT使用了Basename,就是能给每个条目定制名称,是一个SEO策略。修改源码是为了把Basename也保存到备份中去,Wordpress也支持定制名称,这样可以做到URL不变,搜索引擎来源不会受影响。
修改lib/MT/ImportExport.pm的552行处
-----
BASENAME:
<$MTEntryBasename$>
-----
KEYWORDS:
<$MTEntryKeywords$>
BASENAME:
<$MTEntryBasename$>
-----
KEYWORDS:
<$MTEntryKeywords$>
修改代码后到Import/Export中导出备份。
安装步骤已经写过了,安装插件就是将php文件放到wp-content/plugins目录下,然后到后台去激活之。
下载: mt2wp.patch
到管理后台-->选项–>永久连接,一般选项修改为/archives/%category%/%postname%.shtml,这里要注意rewrite规则,apache必须支持rewrite才可以,保存后到首页去看看效果了
July 7th, 2007 at 09:07
[...] MovableType: Perl+(BDB|MySQL) WordPress: PHP+MySQL MovableType迁移到wordpress的笔记 [...]