Wordpress转换到Movable Type的程序

李华伟部落看到的这篇文章,虽然我自己不用wordpress,不过这个东西还是挺多人用的~
复制一份备案~
具体步骤如下:保存以下代码,存为PHP文件.

<?
    header('Content-type: text/plain');
    $hostname="hostname";
    $username = "username";
    $password = "password";
    $dbname = "dbname";
    $db_con = mysql_connect($hostname,$username, $password) or die("Connetion to database failed!");
    mysql_select_db($dbname);
    mysql_query("SET NAMES 'utf8'");
    $query = "SELECT 
    `wp_posts`.`post_date`,
    `wp_posts`.`post_content`,
    `wp_posts`.`post_title`,
    `wp_posts`.`post_name`,
    `wp_users`.`user_nicename`,
    `wp_post2cat`.`category_id`,
    `wp_categories`.`cat_name`, 
    `wp_comments`.`comment_author`,
    `wp_comments`.`comment_content`,
    `wp_comments`.`comment_author_email`,
    `wp_comments`.`comment_author_url`,
    `wp_comments`.`comment_author_IP`,
    `wp_comments`.`comment_date`
    FROM
    `wp_comments`
    RIGHT OUTER JOIN `wp_posts` ON (`wp_comments`.`comment_post_ID` = `wp_posts`.`ID`)
    LEFT OUTER JOIN `wp_users` ON (`wp_posts`.`post_author` = `wp_users`.`ID`)
    INNER  JOIN  `wp_post2cat`  ON (  `wp_posts`.`ID`  =  `wp_post2cat`.`post_ID`  ) 
    LEFT  OUTER  JOIN  `wp_categories`  ON (  `wp_categories`.`cat_ID`  =  `wp_post2cat`.`category_ID`  ) 
    ";
    $result = mysql_query($query);
    if ($result) {
        $numOfRows = mysql_num_rows ($result);
        for ($i = 0; $i < $numOfRows; $i++) {
            if ($prev_entry == mysql_result($result, $i, "post_date")) {
                print_comment($result, $i);
            } else {        
                print_post($result, $i);
                $prev_entry = mysql_result($result, $i, "post_date");
                if (mysql_result($result, $i, "comment_content") != "") {
                    #echo ("-----\n");
                    print_comment($result, $i);
                }
            }
        }
    }
    mysql_close ();
    function print_post($result, $i) {
        echo ("--------\n");
            echo ("AUTHOR: ").stripslashes(mysql_result($result, $i, "user_nicename"))."\n";
            echo ("TITLE: ").stripslashes(mysql_result($result, $i, "post_title"))."\n";
            echo ("STATUS: Publish\n");
            echo ("ALLOW COMMENTS: 2\n");
            //echo ("CONVERT BREAKS: markdown\n");
            echo ("ALLOW PINGS: 0\n");
            echo ("CATEGORY: ").stripslashes(mysql_result($result, $i, "cat_name"))."\n";
            echo ("DATE: ").date("m/d/Y h:m:s A",(strtotime(mysql_result($result, $i, "post_date"))))."\n";
            echo ("-----\n");
            echo ("KEYWORDS:\n");
            echo stripslashes(mysql_result($result, $i, "post_name"))."\n";
            echo ("-----\n");
            echo ("BODY:\n");
            echo stripslashes(str_replace("<br />", "", mysql_result($result, $i, "post_content")))."\n";
            echo ("-----\n");
    }
function print_comment($result, $i) {
$text=stripslashes(str_replace("<br />", "", mysql_result($result, $i, "comment_content")))."\n";
if (0 === strpos($text,'<trackback />')) {
preg_match ("!<trackback /><strong>(.+)</strong>\n(.+)!",$text,$matches);
echo ("PING:\n");
echo ("BLOG NAME: ").stripslashes(mysql_result($result, $i, "comment_author"))."\n";
echo ("URL: ").stripslashes(mysql_result($result, $i, "comment_author_url"))."\n";
echo ("TITLE: $matches[1]\n");
$text = "$matches[2]\n";
} else {
echo ("COMMENT:\n");
echo ("AUTHOR: ").stripslashes(mysql_result($result, $i, "comment_author"))."\n";
echo ("EMAIL: ").stripslashes(mysql_result($result, $i, "comment_author_email"))."\n";
echo ("URL: ").stripslashes(mysql_result($result, $i, "comment_author_url"))."\n";
}
echo ("IP: ").stripslashes(mysql_result($result, $i, "comment_author_ip"))."\n";
echo ("DATE: ").date("m/d/Y h:m:s A",(strtotime(mysql_result($result, $i, "post_date"))))."\n";
echo $text;
echo ("-----\n");
}
?>

然后上传文件到服务器,更改下列参数与Wordpress相同:

$hostname="hostname";$username = "username"; $password = "password";$dbname = "dbname";

1. 根据mysql数据库修改mysql_query("SET NAMES 'utf8'");
2. 运行上传的php文件,将结果另存为
3. 进MT后台控制台,import,搞定!

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

返回主页看更多
狠狠的抽打博主 支付宝 扫一扫