终于用上WP

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

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

php代码:

  1. <?php  
  2.   
  3. include_once 'conf.php';  
  4.   
  5. $buf = '<?xml version="1.0" encoding="UTF-8"?> 
  6. <rss version="2.0" 
  7.     xmlns:excerpt="http://wordpress.org/export/1.0/excerpt/" 
  8.     xmlns:content="http://purl.org/rss/1.0/modules/content/" 
  9.     xmlns:wfw="http://wellformedweb.org/CommentAPI/" 
  10.     xmlns:dc="http://purl.org/dc/elements/1.1/" 
  11.     xmlns:wp="http://wordpress.org/export/1.0/" 
  12. > 
  13.  
  14. <channel> 
  15.     <title>Xiaoxia[PG]</title> 
  16.     <link>http://blog.xiaoxia.org</link> 
  17.     <description>= I am the one! =</description> 
  18.     <pubDate>Sat, 16 Oct 2010 21:51:19 +0000</pubDate> 
  19.     <generator>http://wordpress.org/?v=3.0.1</generator> 
  20.     <language>en</language> 
  21.     <wp:wxr_version>1.0</wp:wxr_version> 
  22.     <wp:base_site_url>http://blog.xiaoxia.org</wp:base_site_url> 
  23.     <wp:base_blog_url>http://blog.xiaoxia.org</wp:base_blog_url> 
  24.     <generator>http://wordpress.org/?v=3.0.1</generator>';  
  25.   
  26. $condition = " ORDER BY `ctime`";  
  27. $query = "SELECT `topic`.*, `type`.`style`, `type`.`name` AS type_name from `topic`  
  28.     LEFT JOIN `type` ON `type`.`type_id`=`topic`.`type_id` 
  29.     $condition";  
  30. $result  = mysql_query($queryor die('Error, query failed' .$query . "<p>".mysql_error()."</p>");  
  31.   
  32. while$row = mysql_fetch_array($result, MYSQL_ASSOC) )  
  33. {  
  34.     $buf .= "<item>\n";  
  35.       
  36.     if$row['style'] ==0 ){  
  37.         $buf .= "<title>" . $row['title'] . "</title>\n";  
  38.     }else{  
  39.         $buf .= "<title>" . $row['name'] . "</title>\n";  
  40.     }  
  41.     $buf .="<link>http://blog.xiaoxia.org/?p=" . $row['topic_id'] . "</link>\n";  
  42.     $buf .="<pubDate>" . date("D, j M Y G:i:s +0800"strtotime($row['ctime']) ) . "</pubDate>\n";  
  43.     $buf .="<dc:creator><![CDATA[xiaoxia]]></dc:creator>\n";  
  44.     $buf .="<category><![CDATA[".$row['type_name']. "]]></category>\n";  
  45.     $buf .="<category domain=\"category\" nicename=\"".$row['type_id']."\"><![CDATA[".$row['type_name']. "]]></category>\n";  
  46.     $buf .="<guid isPermaLink=\"false\">http://blog.xiaoxia.org/?p=" . $row['topic_id'] . "</guid>\n";  
  47.     $buf .="<description></description>\n";  
  48.     if$row['style'] ==0 ){  
  49.         $buf .="<content:encoded><![CDATA[" . $row['content'] . "]]></content:encoded>\n";  
  50.     }else{  
  51.         $buf .="<content:encoded><![CDATA[" . $row['title'] . "\n<!--more-->\n" .$row['content'] . "]]></content:encoded>\n";  
  52.     }  
  53.     $buf .="<excerpt:encoded><![CDATA[]]></excerpt:encoded>\n";  
  54.     $buf .="<wp:post_id>{$row['topic_id']}</wp:post_id>\n";  
  55.     $buf .="<wp:post_date>{$row['ctime']}</wp:post_date>\n";  
  56. //  $buf .="<wp:post_date_gmt>{$row['ctime']}</wp:post_date_gmt>\n";  
  57.     $buf .="<wp:comment_status>open</wp:comment_status>\n";  
  58.     $buf .="<wp:ping_status>open</wp:ping_status>\n";  
  59.     $buf .="<wp:post_name>{$row['name']}</wp:post_name>\n";  
  60.     if$row['private'] )  
  61.         $buf .="<wp:status>private</wp:status>\n";  
  62.     else  
  63.         $buf .="<wp:status>publish</wp:status>\n";  
  64.     $buf .="<wp:post_parent>0</wp:post_parent>\n";  
  65.     $buf .="<wp:menu_order>0</wp:menu_order>\n";  
  66.     $buf .="<wp:post_type>post</wp:post_type>\n";  
  67.     $buf .="<wp:post_password></wp:post_password>\n";  
  68.     $buf .="<wp:is_sticky>0</wp:is_sticky>\n";  
  69.       
  70.     $condition = " WHERE `topic_id`={$row['topic_id']} ORDER BY `ctime`";  
  71.     $query = "SELECT * from `comment` $condition";  
  72.     $result2  = mysql_query($queryor die('Error, query failed!' .$query . "<p>".mysql_error()."</p>");  
  73.     while$row = mysql_fetch_array($result2, MYSQL_ASSOC) )  
  74.     {  
  75.         $buf .= "<wp:comment>\n";  
  76.         $buf .= "<wp:comment_id>{$row['comment_id']}</wp:comment_id>\n";  
  77.         if$row['name']=='xiaoxia' || $row['name']=='Xiaoxia' || $row['name']=='小虾'){  
  78.             $buf .= "<wp:comment_user_id>1</wp:comment_user_id>\n";  
  79.             $row['name']='Xiaoxia';  
  80.             $row['mail']='xiaoxia@xiaoxia.org';  
  81.         }else{  
  82.             $buf .= "<wp:comment_user_id>0</wp:comment_user_id>\n";  
  83.         }  
  84.         $buf .= "<wp:comment_author><![CDATA[{$row['name']}]]></wp:comment_author>\n";  
  85.         $buf .= "<wp:comment_author_email><![CDATA[{$row['mail']}]]></wp:comment_author_email>\n";  
  86.         $buf .= "<wp:comment_author_url></wp:comment_author_url>\n";  
  87.         $buf .= "<wp:comment_author_IP>{$row['ip']}</wp:comment_author_IP>\n";  
  88.         $buf .= "<wp:comment_date>{$row['ctime']}</wp:comment_date>\n";  
  89.         $buf .= "<wp:comment_content><![CDATA[{$row['content']}]]></wp:comment_content>\n";  
  90.         $buf .= "<wp:comment_approved>" . (1 - $row['disabled'] ) . "</wp:comment_approved>\n";  
  91.         $buf .= "<wp:comment_type></wp:comment_type>\n";  
  92.         $buf .= "<wp:comment_parent>0</wp:comment_parent>\n";  
  93.         $buf .= "</wp:comment>\n";  
  94.     }  
  95.     $buf .= "</item>\n";  
  96. }  
  97.   
  98. $buf .= '<item> 
  99.         <title>留言板</title> 
  100.         <link>http://blog.xiaoxia.org/?page_id=2</link> 
  101.         <pubDate>Sat, 16 Oct 2010 21:20:52 +0000</pubDate> 
  102.         <dc:creator><![CDATA[jessica]]></dc:creator> 
  103.          
  104.         <guid isPermaLink="false">http://blog.xiaoxia.org/?page_id=2</guid> 
  105.         <description></description> 
  106.         <content:encoded><![CDATA[这里是留言板。]]></content:encoded> 
  107.         <excerpt:encoded><![CDATA[]]></excerpt:encoded> 
  108.         <wp:post_id>2</wp:post_id> 
  109.         <wp:post_date>2010-10-16 21:20:52</wp:post_date> 
  110.         <wp:post_date_gmt>2010-10-16 21:20:52</wp:post_date_gmt> 
  111.         <wp:comment_status>open</wp:comment_status> 
  112.         <wp:ping_status>open</wp:ping_status> 
  113.         <wp:post_name>留言</wp:post_name> 
  114.         <wp:status>publish</wp:status> 
  115.         <wp:post_parent>0</wp:post_parent> 
  116.         <wp:menu_order>0</wp:menu_order> 
  117.         <wp:post_type>page</wp:post_type> 
  118.         <wp:post_password></wp:post_password> 
  119.         <wp:is_sticky>0</wp:is_sticky>';  
  120.   
  121. $condition = " WHERE `topic_id`=0 ORDER BY `ctime`";  
  122. $query = "SELECT * from `comment` $condition";  
  123. $result2  = mysql_query($queryor die('Error, query failed!' .$query . "<p>".mysql_error()."</p>");  
  124. while$row = mysql_fetch_array($result2, MYSQL_ASSOC) )  
  125. {  
  126.     $buf .= "<wp:comment>\n";  
  127.     $buf .= "<wp:comment_id>{$row['comment_id']}</wp:comment_id>\n";  
  128.     if$row['name']=='xiaoxia' || $row['name']=='Xiaoxia' || $row['name']=='小虾'){  
  129.         $buf .= "<wp:comment_user_id>1</wp:comment_user_id>\n";  
  130.         $row['name']='Xiaoxia';  
  131.         $row['mail']='xiaoxia@xiaoxia.org';  
  132.     }else{  
  133.         $buf .= "<wp:comment_user_id>0</wp:comment_user_id>\n";  
  134.     }  
  135.     $buf .= "<wp:comment_author><![CDATA[{$row['name']}]]></wp:comment_author>\n";  
  136.     $buf .= "<wp:comment_author_email><![CDATA[{$row['mail']}]]></wp:comment_author_email>\n";  
  137.     $buf .= "<wp:comment_author_url></wp:comment_author_url>\n";  
  138.     $buf .= "<wp:comment_author_IP>{$row['ip']}</wp:comment_author_IP>\n";  
  139.     $buf .= "<wp:comment_date>{$row['ctime']}</wp:comment_date>\n";  
  140.     $buf .= "<wp:comment_content><![CDATA[{$row['content']}]]></wp:comment_content>\n";  
  141.     $buf .= "<wp:comment_approved>" . (1 - $row['disabled'] ) . "</wp:comment_approved>\n";  
  142.     $buf .= "<wp:comment_type></wp:comment_type>\n";  
  143.     $buf .= "<wp:comment_parent>0</wp:comment_parent>\n";  
  144.     $buf .= "<wp:comment_user_id>0</wp:comment_user_id>\n";  
  145.     $buf .= "</wp:comment>\n";  
  146. }  
  147. $buf .= '</item>';  
  148.   
  149. $buf .= '   </channel> 
  150. </rss>';  
  151.   
  152. $file_pointer = fopen("wp.xml","w");  
  153. fwrite($file_pointer,$buf);  
  154. fclose($file_pointer);  
  155. ?>  
  156. OK  

终于用上WP》有29个想法

        1. Xiaoxia 文章作者

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

          回复

回复 Blackrose 取消回复

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

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