Hongmu Notes
Home Program Notes Detailed Tutorial on Migrating EmpireCMS Blog Data to WordPress
Program Notes wordpress

Detailed Tutorial on Migrating EmpireCMS Blog Data to WordPress

Detailed Tutorial on Migrating EmpireCMS Blog Data to WordPress

PS1: The second modification, which currently supports the data transfer of classification, article and tag

PS2: If the article ID is always correct, you can try to empty the WordPress article classification data table and relationship table

I used to blog with typecho, and later moved to the empire, but the empire functions too much, the blog with the empire is a little overqualified feeling!

Moreover, I use the blog I often record some important code, these code are I worked hard to write, how can't say white luck, right?

So I think of paying for knowledge, but the empire, I don't want to toss about, simply moved to wordpress!

After all, wordpress is suitable for the blog...... This is not to say that the empire is not fit for construction

The following migration detailed record and code are summarized here.

Step 1: Build a wordpress

The official website can download wordpress, the installation can be installed.

Step 2: Install the tool for importing the data

ad1a1b7183093153

Step 3: Export the data from the empire

Here the export data needs to use code, only export articles and classification, classification url if the rules, can be kept unchanged, if there is a different url form under each classification, that is not good

Build a etow.php in the root directory of your empire website, and then put the following code in, visit this PHP to see xml data, at this time Ctrl + S save, save as xml file

 隐藏内容:付费阅读
<?php
header("Content-type:text/xml");

$site = "https://www.4s5.cn";//修改成自己的网站链接
$sitename = "站点名称";//站点名称,自己修改

echo 
<<<EOD
<?xml version="1.0" encoding="UTF-8" ?>
<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
<!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your site. -->

<!-- To import this information into a WordPress site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Go to Tools: Import in the WordPress admin panel. -->
<!-- 3. Install the "WordPress" importer from the list. -->
<!-- 4. Activate & Run Importer. -->
<!-- 5. Upload this file using the form provided on that page. -->
<!-- 6. You will first be asked to map the authors in this export file to users -->
<!--    on the site. For each author, you may choose to map to an -->
<!--    existing user on the site or to create a new user. -->
<!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
<!--    contained in this file into your site. -->

  <!-- generator="WordPress/6.1.1" created="2023-02-05 09:40" -->
<rss version="2.0"
  xmlns:excerpt="http://wordpress.org/export/1.2/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.2/"
>

<channel>
  <title>{$sitename}</title>
  <link>{$site}</link>
  <description></description>
  <pubDate>Sun, 05 Feb 2023 09:40:05 +0000</pubDate>
  <language>zh-CN</language>
  <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><![CDATA[1810216796]]></wp:author_login><wp:author_email><![CDATA[1810216796@qq.com]]></wp:author_email><wp:author_display_name><![CDATA[1810216796]]></wp:author_display_name><wp:author_first_name><![CDATA[]]></wp:author_first_name><wp:author_last_name><![CDATA[]]></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><![CDATA[{$r['classpath']}]]></wp:category_nicename>
    <wp:category_parent><![CDATA[]]></wp:category_parent>
    <wp:cat_name><![CDATA[{$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><![CDATA[{$s2['classpath']}]]></wp:category_nicename>
    <wp:category_parent><![CDATA[{$r['classpath']}]]></wp:category_parent>
    <wp:cat_name><![CDATA[{$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><![CDATA[{$s3['classpath']}]]></wp:category_nicename>
    <wp:category_parent><![CDATA[{$s2['classpath']}]]></wp:category_parent>
    <wp:cat_name><![CDATA[{$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><![CDATA[{$r['tagname']}]]></wp:tag_slug>
		<wp:tag_name><![CDATA[{$r['tagname']}]]></wp:tag_name>
	</wp:tag>
	<wp:term>
		<wp:term_id>{$r['tagid']}</wp:term_id>
		<wp:term_taxonomy><![CDATA[post_tag]]></wp:term_taxonomy>
		<wp:term_slug><![CDATA[{$r['tagname']}]]></wp:term_slug>
		<wp:term_parent><![CDATA[]]></wp:term_parent>
		<wp:term_name><![CDATA[{$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><![CDATA[category]]></wp:term_taxonomy>
    <wp:term_slug><![CDATA[{$r['classpath']}]]></wp:term_slug>
    <wp:term_parent><![CDATA[]]></wp:term_parent>
    <wp:term_name><![CDATA[{$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><![CDATA[category]]></wp:term_taxonomy>
    <wp:term_slug><![CDATA[{$s2['classpath']}]]></wp:term_slug>
    <wp:term_parent><![CDATA[{$r['classpath']}]]></wp:term_parent>
    <wp:term_name><![CDATA[{$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><![CDATA[category]]></wp:term_taxonomy>
    <wp:term_slug><![CDATA[{$s3['classpath']}]]></wp:term_slug>
    <wp:term_parent><![CDATA[{$r['classpath']}]]></wp:term_parent>
    <wp:term_name><![CDATA[{$s3['classname']}]]></wp:term_name>
  </wp:term>
  ";
    }
    }
}
echo '  <generator>https://wordpress.org/?v=6.1.1</generator>
';

//文章处理
$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('<pre>','<pre class="enlighter-pre" mce-contenteditable="false"><code class="gl">',$r2['newstext']);
    $markdown = str_replace('</pre>','</code></pre>',$markdown);
     
     $markdown = str_replace(' class="title"','',$markdown);
     $markdown = str_replace('\"','"',$markdown);
    $markdown = str_replace('/d/file/','/wp-content/uploads/',$markdown);
    $markdown = str_replace('<h2>个人备注:</h2>','<h4>个人备注:</h4>',$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 .= '<category domain="post_tag" nicename="'.$tagArray[$r3['tagid']].'"><![CDATA['.$tagArray[$r3['tagid']].']]></category>';
    }
    
    
        echo
<<<EOD
<item>
    <title><![CDATA[{$r2['title']}]]></title>
    <link>{$r2['titleurl']}</link>
    <pubDate>Sun, {$time4} Feb {$time2} {$time1} +0000</pubDate>
    <dc:creator><![CDATA[1810216796]]></dc:creator>
    <guid isPermaLink="false">{$site}/?p={$r2['id']}</guid>
    <description></description>
    <content:encoded><![CDATA[{$markdown}]]></content:encoded>
    <excerpt:encoded><![CDATA[]]></excerpt:encoded>
    <wp:post_id>{$r2['id']}</wp:post_id>
    <wp:post_date><![CDATA[{$time2}-{$time3}-{$time4} {$time1}]]></wp:post_date>
    <wp:post_date_gmt><![CDATA[{$time2}-{$time3}-{$time4} {$time1}]]></wp:post_date_gmt>
    <wp:post_modified><![CDATA[{$time2}-{$time3}-{$time4} {$time1}]]></wp:post_modified>
    <wp:post_modified_gmt><![CDATA[{$time2}-{$time3}-{$time4} {$time1}]]></wp:post_modified_gmt>
    <wp:comment_status><![CDATA[open]]></wp:comment_status>
    <wp:ping_status><![CDATA[open]]></wp:ping_status>
    <wp:post_name><![CDATA[{$title}]]></wp:post_name>
    <wp:status><![CDATA[publish]]></wp:status>
    <wp:post_parent>0</wp:post_parent>
    <wp:menu_order>0</wp:menu_order>
    <wp:post_type><![CDATA[post]]></wp:post_type>
    <wp:post_password><![CDATA[]]></wp:post_password>
    <wp:is_sticky>0</wp:is_sticky>
    {$tags}
                    <category domain="category" nicename="{$classpatch}"><![CDATA[{$classname}]]></category>
            <wp:postmeta>
    <wp:meta_key><![CDATA[_edit_last]]></wp:meta_key>
    <wp:meta_value><![CDATA[1]]></wp:meta_value>
    </wp:postmeta>
              <wp:postmeta>
    <wp:meta_key><![CDATA[_wp_page_template]]></wp:meta_key>
    <wp:meta_value><![CDATA[default]]></wp:meta_value>
    </wp:postmeta>
              </item>
EOD;
  
}

echo '
        </channel>
</rss>
  ';

db_close();                        //关闭MYSQL链接
$empire=null; 

?>

Because my blog data is relatively small, about thousands, so directly step exported, if your website data is too much, you can contact me to modify the code for free!

Step 4: Import the wordpress

ad1a1b7183093959

So you can transfer your imperial data to the wordpress

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

What should I do if the Redis Object Cache plug-in cannot be linked after wordpress redis changes the password?

What should I do if the Redis Object Cache plug-in cannot be linked after wordpress redis changes the password? Program Notes wordpress

Problem description: My wordpress site server uses pagoda panel, installed php8.0, and installed redis on the extension panel, and installed Redis Object Cache plug-in in wordpress. In fact, in general, you don't need to do anything, just start it directly. However, it is unsafe for radis not to set a password, which is a risky loophole, so I still think it is better to set a password, …
👁 255
How do I disable revisions and automatic draft saving in WordPress?

How do I disable revisions and automatic draft saving in WordPress? Program Notes wordpress

WordPress's automatic article revision tracking feature logs every time you edit an article in the后台; each revision is recorded as a separate entry in the `wp_posts` table. Due to the interplay between article revisions and automatic saving, the article ID often grows larger over time. While this typically does not cause significant issues for your WordPress installation, an excessive number of article versions can place a considerable burden on your storage space and database...
👁 373
WordPress issue: pages freezing due to image transcoding

WordPress issue: pages freezing due to image transcoding Program Notes wordpress

Last night, while uploading an image, for some reason, the uploaded image was automatically transcoded. Transcoding type: BASE64 encoding. For an image on a website, simply upload it to your server and then access the link – the image will then be displayed. However, there is another approach: directly transcoding the image; then you can simply access the converted image using its encoded URL. Problem description: When an image is relatively small (e.g., only a few KB in size), transcoding it and then hosting it on a website can help avoid...
👁 152
WordPress database query operations

WordPress database query operations Program Notes wordpress

To connect to a database for a WordPress installation, you need to include the `wp-config.php` file in your PHP script. This file contains the database configuration details for WordPress installation and other constants. Here is a simple example demonstrating how to include the `wp-config.php` file and establish a database connection: // Include the wp-config.php file: require...
👁 378
WordPress MySQL Database Table and Subtable Structure Functionality Guide

WordPress MySQL Database Table and Subtable Structure Functionality Guide Program Notes wordpress

WordPress uses a MySQL database. Its data table structure differs slightly from that of conventional databases; data can be stored either in the form of standard data tables or as data elements – the latter approach is less intuitive when viewed directly. To become a developer, you must understand the basic structure of the WordPress database and be able to use it within your own plugins or themes to write to or read from the database. I. Data Tables – As of WordPress...
👁 374

Recommended reading

(Adaptive mobile terminal) new media news and information pbootcms website template IT operation blog website source code download 0715

(Adaptive mobile terminal) new media news and information pbootcms website template IT operation blog website source code download 0715 Practical Collection pbootcms Template

A new media news information and IT operation blog PbootCMS website template, support PC and WAP end. Design style simple information flow, suitable for sharing the Internet industry dynamics, operation dry goods and technical articles. It helps new media practitioners to build their personal brands and influence online. Template display, installation instructions Website background: / admin.php account: admin password: admin decompression password: www.4s5...
👁 43
Responsive training platform teaching software website template 0836

Responsive training platform teaching software website template 0836 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for training platform and educational software companies. Its educational technology-oriented design is perfect for showcasing online training platforms, teaching software, course resources, and technical solutions. It helps education technology firms present their brand online and attract both school and corporate clients. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Common Questions About EyouCMS Installation...
👁 31
Empire CMS source mall virtual supply software download adaptive response mobile phone HTML5 whole station template 052

Empire CMS source mall virtual supply software download adaptive response mobile phone HTML5 whole station template 052 Practical Collection empire template

The entire site is produced using the latest Empire CMS core, making it safe, efficient and operational! The template does not have too many fancy styles and functions, and everything is optimized for the operation of individual webmasters. The webmaster has good resources at hand and can start operations immediately using this entire site template. The entire site adapts to mobile devices such as mobile phones and tablets! A certain fish sells for 800, which is actually copied from someone else’s zblog... Preview image and unzip password 🔒 Hidden content: Check the download page after commenting...
👁 758
(PC + WAP) marketing environmental protection shell powder ecological coating pbootcms website template cyan paint coating website source code download 0716

(PC + WAP) marketing environmental protection shell powder ecological coating pbootcms website template cyan paint coating website source code download 0716 Practical Collection pbootcms Template

A PbootCMS marketing website template for environmental protection shell powder ecological coating and paint and coating industry, using cyan style, support PC and WAP end. The design style is fresh and environmentally friendly, and can display ecological coating products and coating engineering cases. Help paint enterprises to promote green building materials online, to attract more home decoration and engineering customers. Template display, installation instructions website background: / admin.php Account: admin password: ad...
👁 38
Vocational education and training industry website template 0837

Vocational education and training industry website template 0837 Practical Collection Yiyou template

A eyoucms website template for the vocational education and training industry. Design style of professional education, can show vocational education courses, training programs, employment services and teachers. It helps vocational training institutions to attract students online and enhance brand awareness. Template display, installation instructions website background: / login.php account: admin password: admin related articles easy CMS installation FAQ summary easy CM...
👁 32
(Independent mobile version) blue marketing network company mobile website template general enterprise website wap website source code 0717

(Independent mobile version) blue marketing network company mobile website template general enterprise website wap website source code 0717 Practical Collection pbootcms Template

This independent mobile version of the blue marketing network company template, is PbootCMS to build the general enterprise WAP website quality choice. The design style is modern and simple, suitable for IT, network technology companies to display services and cases. It helps enterprises to build a professional brand image on the mobile terminal and attract potential customers. Template display, installation instructions Website background: / admin.php account: admin password: admin decompression password: w...
👁 51