WordPress的家


几次思想斗争以后,总算下了狠心将小站迁移到了wordpress

迁移的大致成绩如下:

  • 所有文章页全部迁移成功,文章标签只能后续手工做。
  • 评论迁移了大部分,部分评论由于格式问题无法被迁移。
  • 网站模板全部丢弃。
  • 其余的数据全部丢弃。
  • 原先的链接全部碎掉,需要小幅的hack。

之前的小站使用drupal,由于系统的数据库仅支持postgresql,Drupal似乎是唯一的选择。等到网站上线后,忽然间发觉再要移植数据库几乎是不可能的。postgresql并不是那么普遍,只是至少在国内没有几家能够提供这个平台,兼容性成了问题。

wordpress可以说是最近发展最快的系统,对于Ajax和SEO也支持的绝佳,种种优势不言而喻。

litrin本人经过这一段时间,CSS和PHP的功力大幅下降——糟糕的页面布局就是最好的例证:-)

最后,奉上转移脚本,希望能够给同样困扰的朋友些许帮助。

<?php
//Wordpress的URL路径
$wpURL = ‘http://www.litrin.net/’;
//目标数据库(mysql)设置
$mysqlServer = ‘localhost’;
$mysqlUser = ”;
$mysqlPasswd = ”;
$mysqlDB = ”;
//源数据库(pgsql)设置
$pgsqlServer = ‘localhost’;
$pgsqlUser = ”;
$pgsqlPasswd = ”;
$pgsqlDB = ”;
$mysql = mysql_connect($mysqlServer, $mysqlUser, $mysqlPasswd);
mysql_select_db($mysqlDB);
$pgsql = pg_connect(“host=”.$pgsqlServer.” port=5432 dbname=”.$pgsqlDB.” user=”.$pgsqlUser.” password=”.$pgsqlPasswd);
//先期准备
echo ‘Start import…n’;
mysql_query(‘SET NAME UTF8′);
mysql_query(‘TRUNCATE `wp_posts`’);
mysql_query(‘TRUNCATE `wp_comments`’);
//文章导入
echo ‘Start import node…n’;
$SQL = “SELECT nid, title, body, created, changed FROM node ORDER BY nid “;
$result = pg_query($pgsql, $SQL);
while ( $arr = pg_fetch_array($result, NULL, PGSQL_ASSOC) ){
 $title = $arr[title];
 $body = $arr[body];
 $createDate = date(DATE_ATOM, $arr[created]);
 $createDate_gmt = date(DATE_ATOM, $arr[created] – 8 * 3600);
 $changedDate = date(DATE_ATOM, $arr[changed]);
 $changedDate_gmt = date(DATE_ATOM, $arr[changed] – 8 * 3600);
 $id = $arr[nid];
 $postType = $wpURL . “?p=” . $id ;
 
 $sqlIns = “INSERT INTO `wp_posts`
    (`ID`,`post_author`, `post_date`, `post_date_gmt`, `post_content`,
    `post_title`, `post_category`, `post_excerpt`, `post_status`, `comment_status`,
    `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`,
    `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`,
    `post_type`, `post_mime_type`, `comment_count`)
   VALUES (
         ”.$id.”,1, ‘”.$createDate.”‘, ‘”.$createDate_gmt.”‘, ‘”.$body.”‘,
    ’”.$title.”‘, 0, ”, ‘publish’, ‘open’, ‘open’,
    ”, ‘”.$title.”‘, ”, ”, ‘”.$changedDate.”‘, ‘”.$changedDate_gmt.”‘,
    ”, 0, ‘”.$postType.”‘, 0, ‘post’, ”, 0)”;
 
 $query = mysql_query($sqlIns);
 
}
//评论导入
echo ‘Start import comment… n ‘;
$SQL= “SELECT cid, nid, name, homepage, timestamp, comment FROM comments ORDER BY cid”;
$result = pg_query($pgsql, $SQL);
while ( $arr = pg_fetch_array($result, NULL, PGSQL_ASSOC) ){
 $sqlIns= “INSERT INTO `wp_comments`
    (`comment_ID`, `comment_post_ID`, `comment_author`, `comment_author_email`,
    `comment_author_url`, `comment_author_IP`, `comment_date`, `comment_date_gmt`,
    `comment_content`, `comment_karma`, `comment_approved`, `comment_agent`,
    `comment_type`, `comment_parent`, `user_id`)
   VALUES (“.$arr[cid].”, “.$arr[nid].”, ‘”.$arr[name].”‘, ”, ‘”.$arr[homepage].”‘,
    ”, ‘”.date(DATE_ATOM, $arr[timestamp]).”‘, ‘”.date(DATE_ATOM, $arr[timestamp] – 8 * 3600).”‘,
    ’”.$arr[comment].”‘, 0, ‘1′, ”, ”, 0, “.$arr[uid].”)”;
 
 $query = mysql_query($sqlIns); 
 
}
//评论整理
echo ‘Start arrage comment… n’;
$SQL= “SELECT comment_post_ID, count( `comment_ID` ) AS count FROM `wp_comments` GROUP BY `comment_post_ID` “;
$query = mysql_query($SQL);
while ($arr = mysql_fetch_array($query)){
 $sqlUp = “update wp_posts set comment_count = “.$arr[count].” where ID =”.$arr[comment_post_ID].”";
 mysql_query ($sqlUp);
}
mysql_close($mysql);
pg_close($pgsql);
echo ‘All finished! n’;
?>

,

  1. #1 by smallfish on 2009年03月20日 - 14:17

    你好,我也是刚用wordpress,我有个问题想请教:无论我用哪个模板,我右边栏的目录,分类这些随着我的BLOG文章发布越来越多都跑到右下边去了,不能像你的BLOG这样右边栏和左边日志平行,我使用风格的时候看它风格模板都是好的,不知道该修改哪个文件,谢谢!

  2. #2 by 摇滚 on 2010年03月31日 - 13:33

    从blogsearch搜到了这篇文章,真的很不错,希望能看到更多的新内容,已经订阅了rssfeed,祝博主好运:)

  3. #3 by Evelyn Reed on 2010年05月14日 - 18:02

    i host 5 of my blogs on Blogspot and it is really good for beginners. but if you want something with more features, nothing beats wordpress’::

(will not be published)