终于用上WP

花了一天时间,奋战10多个小时。
终于比较成功地把原博客的数据库转移到现在的wordpress上来!
感觉wordpress真的慢得可怜,在速度上肯定比之前的慢很多,不过功能上也满足了。

我之前以为要直接把mysql里wp的数据库挖出来看看,后来发现通过后台管理面板的导入工具,可以很方便得导入符合一定格式的xml文件。所以,我花了一点心思写了一段php代码,把之前的数据库内容导出来,以wp格式输出来。
不过不是很顺利,我发现wp的数据库里没有单个帖子访问量的统计,需要使用插件才能实现这个功能。这个比较棘手,我后来直接把原来访问量的数据扔掉了,有点可惜,呵呵~

php代码:


<?php

include_once 'conf.php';

$buf = '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:excerpt="http://wordpress.org/export/1.0/excerpt/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:wp="http://wordpress.org/export/1.0/"
>

<channel>
	<title>Xiaoxia[PG]</title>
	<link>http://blog.xiaoxia.org</link>
	<description>= I am the one! =</description>
	<pubDate>Sat, 16 Oct 2010 21:51:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<language>en</language>
	<wp:wxr_version>1.0</wp:wxr_version>
	<wp:base_site_url>http://blog.xiaoxia.org</wp:base_site_url>
	<wp:base_blog_url>http://blog.xiaoxia.org</wp:base_blog_url>
	<generator>http://wordpress.org/?v=3.0.1</generator>';

$condition = " ORDER BY `ctime`";
$query = "SELECT `topic`.*, `type`.`style`, `type`.`name` AS type_name from `topic` 
	LEFT JOIN `type` ON `type`.`type_id`=`topic`.`type_id`
	$condition";
$result  = mysql_query($query) or die('Error, query failed' .$query . "<p>".mysql_error()."</p>");

while( $row = mysql_fetch_array($result, MYSQL_ASSOC) )
{
	$buf .= "<item>\n";
	
	if( $row['style'] ==0 ){
		$buf .= "<title>" . $row['title'] . "</title>\n";
	}else{
		$buf .= "<title>" . $row['name'] . "</title>\n";
	}
	$buf .="<link>http://blog.xiaoxia.org/?p=" . $row['topic_id'] . "</link>\n";
	$buf .="<pubDate>" . date("D, j M Y G:i:s +0800", strtotime($row['ctime']) ) . "</pubDate>\n";
	$buf .="<dc:creator><![CDATA[xiaoxia]]></dc:creator>\n";
	$buf .="<category><![CDATA[".$row['type_name']. "]]></category>\n";
	$buf .="<category domain=\"category\" nicename=\"".$row['type_id']."\"><![CDATA[".$row['type_name']. "]]></category>\n";
	$buf .="<guid isPermaLink=\"false\">http://blog.xiaoxia.org/?p=" . $row['topic_id'] . "</guid>\n";
	$buf .="<description></description>\n";
	if( $row['style'] ==0 ){
		$buf .="<content:encoded><![CDATA[" . $row['content'] . "]]></content:encoded>\n";
	}else{
		$buf .="<content:encoded><![CDATA[" . $row['title'] . "\n<!--more-->\n" .$row['content'] . "]]></content:encoded>\n";
	}
	$buf .="<excerpt:encoded><![CDATA[]]></excerpt:encoded>\n";
	$buf .="<wp:post_id>{$row['topic_id']}</wp:post_id>\n";
	$buf .="<wp:post_date>{$row['ctime']}</wp:post_date>\n";
//	$buf .="<wp:post_date_gmt>{$row['ctime']}</wp:post_date_gmt>\n";
	$buf .="<wp:comment_status>open</wp:comment_status>\n";
	$buf .="<wp:ping_status>open</wp:ping_status>\n";
	$buf .="<wp:post_name>{$row['name']}</wp:post_name>\n";
	if( $row['private'] )
		$buf .="<wp:status>private</wp:status>\n";
	else
		$buf .="<wp:status>publish</wp:status>\n";
	$buf .="<wp:post_parent>0</wp:post_parent>\n";
	$buf .="<wp:menu_order>0</wp:menu_order>\n";
	$buf .="<wp:post_type>post</wp:post_type>\n";
	$buf .="<wp:post_password></wp:post_password>\n";
	$buf .="<wp:is_sticky>0</wp:is_sticky>\n";
	
	$condition = " WHERE `topic_id`={$row['topic_id']} ORDER BY `ctime`";
	$query = "SELECT * from `comment` $condition";
	$result2  = mysql_query($query) or die('Error, query failed!' .$query . "<p>".mysql_error()."</p>");
	while( $row = mysql_fetch_array($result2, MYSQL_ASSOC) )
	{
		$buf .= "<wp:comment>\n";
		$buf .= "<wp:comment_id>{$row['comment_id']}</wp:comment_id>\n";
		if( $row['name']=='xiaoxia' || $row['name']=='Xiaoxia' || $row['name']=='小虾'){
			$buf .= "<wp:comment_user_id>1</wp:comment_user_id>\n";
			$row['name']='Xiaoxia';
			$row['mail']='[email protected]';
		}else{
			$buf .= "<wp:comment_user_id>0</wp:comment_user_id>\n";
		}
		$buf .= "<wp:comment_author><![CDATA[{$row['name']}]]></wp:comment_author>\n";
		$buf .= "<wp:comment_author_email><![CDATA[{$row['mail']}]]></wp:comment_author_email>\n";
		$buf .= "<wp:comment_author_url></wp:comment_author_url>\n";
		$buf .= "<wp:comment_author_IP>{$row['ip']}</wp:comment_author_IP>\n";
		$buf .= "<wp:comment_date>{$row['ctime']}</wp:comment_date>\n";
		$buf .= "<wp:comment_content><![CDATA[{$row['content']}]]></wp:comment_content>\n";
		$buf .= "<wp:comment_approved>" . (1 - $row['disabled'] ) . "</wp:comment_approved>\n";
		$buf .= "<wp:comment_type></wp:comment_type>\n";
		$buf .= "<wp:comment_parent>0</wp:comment_parent>\n";
		$buf .= "</wp:comment>\n";
	}
	$buf .= "</item>\n";
}

$buf .= '<item>
		<title>留言板</title>
		<link>http://blog.xiaoxia.org/?page_id=2</link>
		<pubDate>Sat, 16 Oct 2010 21:20:52 +0000</pubDate>
		<dc:creator><![CDATA[jessica]]></dc:creator>
		
		<guid isPermaLink="false">http://blog.xiaoxia.org/?page_id=2</guid>
		<description></description>
		<content:encoded><![CDATA[这里是留言板。]]></content:encoded>
		<excerpt:encoded><![CDATA[]]></excerpt:encoded>
		<wp:post_id>2</wp:post_id>
		<wp:post_date>2010-10-16 21:20:52</wp:post_date>
		<wp:post_date_gmt>2010-10-16 21:20:52</wp:post_date_gmt>
		<wp:comment_status>open</wp:comment_status>
		<wp:ping_status>open</wp:ping_status>
		<wp:post_name>留言</wp:post_name>
		<wp:status>publish</wp:status>
		<wp:post_parent>0</wp:post_parent>
		<wp:menu_order>0</wp:menu_order>
		<wp:post_type>page</wp:post_type>
		<wp:post_password></wp:post_password>
		<wp:is_sticky>0</wp:is_sticky>';

$condition = " WHERE `topic_id`=0 ORDER BY `ctime`";
$query = "SELECT * from `comment` $condition";
$result2  = mysql_query($query) or die('Error, query failed!' .$query . "<p>".mysql_error()."</p>");
while( $row = mysql_fetch_array($result2, MYSQL_ASSOC) )
{
	$buf .= "<wp:comment>\n";
	$buf .= "<wp:comment_id>{$row['comment_id']}</wp:comment_id>\n";
	if( $row['name']=='xiaoxia' || $row['name']=='Xiaoxia' || $row['name']=='小虾'){
		$buf .= "<wp:comment_user_id>1</wp:comment_user_id>\n";
		$row['name']='Xiaoxia';
		$row['mail']='[email protected]';
	}else{
		$buf .= "<wp:comment_user_id>0</wp:comment_user_id>\n";
	}
	$buf .= "<wp:comment_author><![CDATA[{$row['name']}]]></wp:comment_author>\n";
	$buf .= "<wp:comment_author_email><![CDATA[{$row['mail']}]]></wp:comment_author_email>\n";
	$buf .= "<wp:comment_author_url></wp:comment_author_url>\n";
	$buf .= "<wp:comment_author_IP>{$row['ip']}</wp:comment_author_IP>\n";
	$buf .= "<wp:comment_date>{$row['ctime']}</wp:comment_date>\n";
	$buf .= "<wp:comment_content><![CDATA[{$row['content']}]]></wp:comment_content>\n";
	$buf .= "<wp:comment_approved>" . (1 - $row['disabled'] ) . "</wp:comment_approved>\n";
	$buf .= "<wp:comment_type></wp:comment_type>\n";
	$buf .= "<wp:comment_parent>0</wp:comment_parent>\n";
	$buf .= "<wp:comment_user_id>0</wp:comment_user_id>\n";
	$buf .= "</wp:comment>\n";
}
$buf .= '</item>';

$buf .= '	</channel>
</rss>';

$file_pointer = fopen("wp.xml","w");
fwrite($file_pointer,$buf);
fclose($file_pointer);
?>
OK

终于用上WP》有29个想法

        1. Xiaoxia 文章作者

          不是啊。。分类目录是在右边栏的。你是使用哪个浏览器?要不要按Ctrl+F5刷新一下?

          回复

发表回复

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

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据