化繁为简，帝国cms博客数据迁移至wordpress详细教程
一 前言5Var美食谷（5var.com）是我很早就建立的一个美食网站，运行几年流量还是少的可怜，可能是来自搜索引擎的流量太少了，毕竟酒香也怕巷子深，本着死马当活马医的想法，索性就搬到wordpress，毕竟wordpress才适合博客……这里并不是说帝国不适合建站。二 转换教程以下迁移详细记录与代码。1 第一步：搭建wordpress官网下载wordpress即可，安装的时候正常安装即可。2 第二步：安装导入数据的工具可以安装wordpress导入器插件。3 第三步：导出帝国的数据这里导出数据就需要用到代码了，只导出文章和分类，分类url如果规则的话，可以保留不变，如果每个分类下都有不同的url形式的话，那就不行了。在你帝国网站根目录建立一个etow.php，然后将下面的代码放进去，访问这个PHP即可看到xml数据，这时候Ctrl+S保存，保存为xml文件。etow.php代码如下：{hide}需要隐藏的内容<?php header("Content-type:text/xml"); $site = "https://www.5var.com";//修改成自己的网站链接 $sitename = "5Var美食谷";//站点名称，自己修改 echo <<<EOD <?xml version="1.0" encoding="UTF-8" ?> {$sitename} {$site} Sun, 05 Feb 2023 09:40:05 +0000 zh-CN <wp:wxr_version>1.2</wp:wxr_version> <wp:base_site_url>{$site}</wp:base_site_url> <wp:base_blog_url>{$site}</wp:base_blog_url> <wp:author><wp:author_id>1</wp:author_id><wp:author_login> 1810216796 </wp:author_login><wp:author_email> 1810216796@qq.com </wp:author_email><wp:author_display_name> 1810216796 </wp:author_display_name><wp:author_first_name> </wp:author_first_name><wp:author_last_name> </wp:author_last_name></wp:author> EOD; require('e/class/connect.php'); //引入数据库配置文件和公共函数文件 require('e/class/db_sql.php'); //引入数据库操作文件 $link=db_connect(); //连接MYSQL $empire=new mysqlquery(); //声明数据库操作类 $allcass = array(); $allcass_name = array(); //分类处理 $sql=$empire->query("SELECT classid,classpath,classname FROM `phome_enewsclass` where bclassid = 0"); //一级分类 while($r=$empire->fetch($sql)) //循环获取查询记录 { echo" <wp:category> <wp:term_id>{$r['classid']}</wp:term_id> <wp:category_nicename> {$r['classpath']} </wp:category_nicename> <wp:category_parent> </wp:category_parent> <wp:cat_name> {$r['classname']} </wp:cat_name> </wp:category> "; $allcass[$r['classid']] = $r['classpath']; $allcass_name[$r['classid']] = $r['classname']; $sql2=$empire->query("select classid,classpath,classname from {$dbtbpre}enewsclass where bclassid=$r[classid] "); //二级分类 while($s2=$empire->fetch($sql2)){ $s2['classpath'] = str_replace($r['classpath'].'/','',$s2['classpath']); echo "<wp:category> <wp:term_id>{$s2['classid']}</wp:term_id> <wp:category_nicename> {$s2['classpath']} </wp:category_nicename> <wp:category_parent> {$r['classpath']} </wp:category_parent> <wp:cat_name> {$s2['classname']} </wp:cat_name> </wp:category> "; $allcass[$s2['classid']] = $s2['classpath']; $allcass_name[$s2['classid']] = $s2['classname']; $sql3=$empire->query("select classid,classpath,classname from {$dbtbpre}enewsclass where bclassid=$s2[classid] "); //二级分类 while($s3=$empire->fetch($sql3)){ $s3['classpath'] = str_replace($s2['classpath'].'/','',$s3['classpath']); $allcass[$s3['classid']] = $s3['classpath']; $allcass_name[$s3['classid']] = $s3['classname']; echo "<wp:category> <wp:term_id>{$s3['classid']}</wp:term_id> <wp:category_nicename> {$s3['classpath']} </wp:category_nicename> <wp:category_parent> {$s2['classpath']} </wp:category_parent> <wp:cat_name> {$s3['classname']} </wp:cat_name> </wp:category> "; } } } //TAG处理 $sql=$empire->query("SELECT * FROM `phome_enewstags`"); while($r=$empire->fetch($sql)) //循环获取查询记录 { $r['tagid'] = $r['tagid'] + 24; echo " <wp:tag> <wp:term_id>{$r['tagid']}</wp:term_id> <wp:tag_slug> {$r['tagname']} </wp:tag_slug> <wp:tag_name> {$r['tagname']} </wp:tag_name> </wp:tag> <wp:term> <wp:term_id>{$r['tagid']}</wp:term_id> <wp:term_taxonomy> post_tag </wp:term_taxonomy> <wp:term_slug> {$r['tagname']} </wp:term_slug> <wp:term_parent> </wp:term_parent> <wp:term_name> {$r['tagname']} </wp:term_name> </wp:term> "; $tagArray[$r['tagid']] = $r['tagname']; } //term处理 $sql=$empire->query("SELECT classid,classpath,classname FROM `phome_enewsclass` where bclassid = 0"); while($r=$empire->fetch($sql)) //循环获取查询记录 { echo" <wp:term> <wp:term_id>{$r['classid']}</wp:term_id> <wp:term_taxonomy> category </wp:term_taxonomy> <wp:term_slug> {$r['classpath']} </wp:term_slug> <wp:term_parent> </wp:term_parent> <wp:term_name> {$r['classname']} </wp:term_name> </wp:term> "; $sql2=$empire->query("select classid,classpath,classname from {$dbtbpre}enewsclass where bclassid=$r[classid] "); while($s2=$empire->fetch($sql2)){ $s2['classpath'] = str_replace($r['classpath'].'/','',$s2['classpath']); echo "<wp:term> <wp:term_id>{$s2['classid']}</wp:term_id> <wp:term_taxonomy> category </wp:term_taxonomy> <wp:term_slug> {$s2['classpath']} </wp:term_slug> <wp:term_parent> {$r['classpath']} </wp:term_parent> <wp:term_name> {$s2['classname']} </wp:term_name> </wp:term> "; $sql3=$empire->query("select classid,classpath,classname from {$dbtbpre}enewsclass where bclassid=$s2[classid] "); while($s3=$empire->fetch($sql3)){ $s3['classpath'] = str_replace($s2['classpath'].'/','',$s3['classpath']); echo "<wp:term> <wp:term_id>{$s3['classid']}</wp:term_id> <wp:term_taxonomy> category </wp:term_taxonomy> <wp:term_slug> {$s3['classpath']} </wp:term_slug> <wp:term_parent> {$r['classpath']} </wp:term_parent> <wp:term_name> {$s3['classname']} </wp:term_name> </wp:term> "; } } } echo ' https://wordpress.org/?v=6.1.1 '; //文章处理 $sql=$empire->query("SELECT * FROM `phome_ecms_news`"); //文章处理 while($r2=$empire->fetch($sql)) //循环获取查询记录 { // $r2['titleurl'] = str_replace('www','wp',$r2['titleurl']); $time1 = date("H:i:s",$r2['lastdotime']); $time2 = date("Y",$r2['lastdotime']); $time3 = date("m",$r2['lastdotime']); $time4 = date("d",$r2['lastdotime']); $title = urlencode($r2['title']); $classname = $allcass_name[$r2['classid']]; $classpatch = $allcass[$r2['classid']]; // $markdown = $converter->convert($r2['newstext']); $markdown = str_replace(' ',' ',$r2['newstext']); $markdown = str_replace(' ',' ',$markdown); $markdown = str_replace(' class="title"','',$markdown); $markdown = str_replace('\"','"',$markdown); $markdown = str_replace('/d/file/','/wp-content/uploads/',$markdown); $markdown = str_replace(' 个人备注： ',' 个人备注： ',$markdown); $tags = ''; //tag查询 $sql2 = $empire->query("SELECT * FROM `phome_enewstagsdata` WHERE `id` = {$r2['id']} "); while($r3=$empire->fetch($sql2)){ $r3['tagid'] = $r3['tagid'] + 24; $tags .= ' '.$tagArray[$r3['tagid']].' '; } echo <<<EOD {$r2['title']} {$r2['titleurl']} Sun, {$time4} Feb {$time2} {$time1} +0000 <dc:creator> 1810216796 </dc:creator> {$site}/?p={$r2['id']} <content:encoded> {$markdown} </content:encoded> <excerpt:encoded> </excerpt:encoded> <wp:post_id>{$r2['id']}</wp:post_id> <wp:post_date> {$time2}-{$time3}-{$time4} {$time1} </wp:post_date> <wp:post_date_gmt> {$time2}-{$time3}-{$time4} {$time1} </wp:post_date_gmt> <wp:post_modified> {$time2}-{$time3}-{$time4} {$time1} </wp:post_modified> <wp:post_modified_gmt> {$time2}-{$time3}-{$time4} {$time1} </wp:post_modified_gmt> <wp:comment_status> open </wp:comment_status> <wp:ping_status> open </wp:ping_status> <wp:post_name> {$title} </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> post </wp:post_type> <wp:post_password> </wp:post_password> <wp:is_sticky>0</wp:is_sticky> {$tags} {$classname} <wp:postmeta> <wp:meta_key> _edit_last </wp:meta_key> <wp:meta_value> 1 </wp:meta_value> </wp:postmeta> <wp:postmeta> <wp:meta_key> _wp_page_template </wp:meta_key> <wp:meta_value> default </wp:meta_value> </wp:postmeta> EOD; } echo ' '; db_close(); //关闭MYSQL链接 $empire=null; ?>{/hide}4第四步：导入wordpress这样便可以把你帝国的数据转移到wordpress里面了。