申请友情连接 MovableType平滑迁移至WordPress
Sep 06
作者: 肖建彬 | 可以转载, 转载时务必以超链接形式标明文章原始出处和作者信息及版权声明
网址:http://www.xiaojb.com/archives/it/mt2wp-howto.shtml

安装好wordpress后,需要将MovableType的数据导入其中,难题是保证每一篇博客的url不变,下边步骤就是我的做法。

  1. 修改MT的源码,导出备份
  2. 我的MT使用了Basename,就是能给每个条目定制名称,是一个SEO策略。修改源码是为了把Basename也保存到备份中去,Wordpress也支持定制名称,这样可以做到URL不变,搜索引擎来源不会受影响。
    修改lib/MT/ImportExport.pm的552行处

    -----
    BASENAME:
    <$MTEntryBasename$>
    -----
    KEYWORDS:
    <$MTEntryKeywords$>

    修改代码后到Import/Export中导出备份。

  3. 安装WP,并安装和启用插件Jerome’s Keywords
  4. 安装步骤已经写过了,安装插件就是将php文件放到wp-content/plugins目录下,然后到后台去激活之。

  5. 修改WP源码,使其支持Basename和Keywords的导入
  6. 下载: mt2wp.patch
    1. --- wordpress.org/wp-admin/import/mt.php    2006-05-19 14:22:55.000000000 +0800
    2. +++ wordpress/wp-admin/import/mt.php    2006-09-06 17:59:47.000000000 +0800
    3. @@ -179,6 +179,7 @@
    4.              if ('' != trim($post)) {
    5.                  ++ $i;
    6.                  unset ($post_categories);
    7. +                $post_name = '';
    8.  
    9.                  // Take the pings out first
    10.                  preg_match("|(-----\n\nPING:.*)|s", $post, $pings);
    11. @@ -188,9 +189,14 @@
    12.                  preg_match("|(-----\nCOMMENT:.*)|s", $post, $comments);
    13.                  $post = preg_replace("|(-----\nCOMMENT:.*)|s", '', $post);
    14.  
    15. -                // We ignore the keywords
    16. +                preg_match("|-----\nKEYWORDS:(.*)|s", $post, $keywords);
    17. +                $post_keywords = $wpdb->escape(trim($keywords[1]));
    18.                  $post = preg_replace("|(-----\nKEYWORDS:.*)|s", '', $post);
    19.  
    20. +                preg_match("|-----\nBASENAME:(.*)|s", $post, $basename);
    21. +                $post_name = $wpdb->escape(trim($basename[1]));
    22. +                $post = preg_replace("|(-----\nBASENAME:.*)|s", '', $post);
    23. +
    24.                  // We want the excerpt
    25.                  preg_match("|-----\nEXCERPT:(.*)|s", $post, $excerpt);
    26.                  $post_excerpt = $wpdb->escape(trim($excerpt[1]));
    27. @@ -225,6 +231,12 @@
    28.                          case 'TITLE' :
    29.                              $post_title = $wpdb->escape($value);
    30.                              break;
    31. +                        case 'KEYWORDS' :
    32. +                            $post_keywords = $value;
    33. +                            break;
    34. +                        case 'BASENAME' :
    35. +                            $post_name = $wpdb->escape($value);
    36. +                            break;
    37.                          case 'STATUS' :
    38.                              // "publish" and "draft" enumeration items match up; no change required
    39.                              $post_status = $value;
    40. @@ -281,8 +293,14 @@
    41.  
    42.                      $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor
    43.  
    44. -                    $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');
    45. +                    $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');
    46.                      $post_id = wp_insert_post($postdata);
    47. +                    if($post_keywords && $post_keywords!='-----') {
    48. +                        if(strstr($post_keywords,'-----')) {
    49. +                            $post_keywords = trim(str_replace('-----','',$post_keywords));
    50. +                        }
    51. +                        add_post_meta($post_id, 'keywords', $post_keywords);
    52. +                    }
    53.                      // Add categories.
    54.                      if (0 != count($post_categories)) {
    55.                          wp_create_categories($post_categories, $post_id);
  7. 修改永久连接(Permalink)选项
  8. 到管理后台-->选项–>永久连接,一般选项修改为/archives/%category%/%postname%.shtml,这里要注意rewrite规则,apache必须支持rewrite才可以,保存后到首页去看看效果了

One Response to “MovableType->WorPress平滑迁移步骤”

  1. MovableType平滑迁移至WordPress Says:

    [...] MovableType: Perl+(BDB|MySQL) WordPress: PHP+MySQL MovableType迁移到wordpress的笔记 [...]

Leave a Reply