从WordPress导出数据到Movable Type的方法
2010年2月12日星期五 | | |我们MT的阵营里有多了一个。。。本来想说生力军、猛将之类的话,但是一想。。。这家伙说都不知道能坚持blogging多久。算了,还是不给他下什么结论了。
本文主要是说从wp到MT的转换的方法。为什么轮到我说?
因为我在网上找了半天N多从MT转到WP的,却不见逆行者。。。没眼光啊没眼光。
不过还好终于被我找到了一个方法,从wordpress转换到movabletype。闲话就不说了,下面是转换方法:
<? header('Content-type: text/plain'); $hostname="localhost"; $username = "databaseuser"; $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"); } ?>
提示:上述代码显示不全只是本站模版的原因,直接复制就可以得到全部代码
修改上述文件的数据库信息。还要注意红色的部分,根据自己的情况修改。其中第二处就是MT里面的"转换换行符"的意思咯。
ok,保存成xxx.php上传到wp的目录,运行之,复制生成页面的内容,接下来,用MT的同志们都应该知道怎么导入吧?
我就不多说了,enjoy!
后注:生成的内容里会有ALLOW COMMENTS: 2 这一句,我不知道什么意思,不过我知道MT的导入文件里,ALLOW COMMENTS: 1代表允许评论(0代表关闭评论)。所以我整体批量地替换了ALLOW COMMENTS: 2为ALLOW COMMENTS: 1然后,导入没有出问题。
本站不欢迎全文转载,如需转载请阅读本站版权声明。
http://www.dimlau.com/blog/2006/12/wordpress-to-movabletype.html
谢谢光临本站: http://home.benz.la 共享无限.. 转载请注明出处..
我的QQ空间
NOD32 Username And Password 备用 2010/02/12
Username: EAV-27525750Password: bdxk628s6xUsername: EAV-2721...