Source: http://www.sjyhome.com/php/wp-to-pc-sql.html
Is the access speed of WordPress not flattering? Then try to generate a pure static phpcms, guaranteed to make your Web page access speed has a quality point to soar!
Why Choose PHPCMS? See Reasons to choose Phpcms
First of all we score precipitation, the conversion process must face several problems, the following is my analysis
The article ID must be consistent, because in most cases the URL of the article is generated based on the ID, which must be done to ensure that the original article can continue to be accessed.
- Article URL must be consistent, some with WP's small partners used postname to define the article URL, also do not have a relationship, in phpcms also make a URL custom field (see phpcms article content page How to customize the URL), and then based on my method to convert.
- Release time is best similar, you do not want users to see your entire site of the article is turned around the same day it? So to the WP article release time also turn around.
- The most important thing is the title and content of the article, the 2 kind also moved over after basically transfer completed.
Database conversion work started
Go to WP background, select Tools-Export, select article, status is published, finally download the exported file, we got an XML file, I named him Wp.xml
Originally above that step I want to export through the database, but WP database in the presence of drafts, the latest version, images and other chaotic information, although you can also set conditions to export, but there is no way to the above convenient.
Now WP all the important articles have been exported, open wp.xml, we need to save the file data through PHP to the array, so as to facilitate the import into the PHPCMS database. However, some data is not recognized when reading the file, so it is necessary to do the replacement work first to standardize the data.
The article ID <wp:post_id> content <content:encoded> and publish time <wp:post_date> are not recognized in the data we want, so search ' wp:post_id ' is replaced with ' post_id ' search ' content:encoded ' replaced with ' content ', search ' wp:post_date ' replaced by ' post_date ', now we need the data are already standard, began to write PHP code
<?php $doc = new DOMDocument (); $doc->load (' wp.xml '); Read XML file $items = $doc->getelementsbytagname ("item"), foreach ($items as $item) {$post _ids = $item->GETELEMENTSB Ytagname ("post_id"); $post _id = $post _ids->item (0)->nodevalue; $titles = $item->getelementsbytagname ("title"); $title = $titles->item (0)->nodevalue; $contents = $item->getelementsbytagname ("content"); $content = $contents->item (0)->nodevalue; $post _dates = $item->getelementsbytagname ("post_date"); $post _date = $post _dates->item (0)->nodevalue; $links = $item->getelementsbytagname ("link"); $link = $links->item (0)->nodevalue; $arr []=array ($post _id, $title, $content, $link, $post _date);} Print_r ($arr);? >
The data we want is already printed in the browser, in order to see a clearer structure, see the results in the Web source code mode.
Next, we need to connect the database, and follow the PHPCMS database storage rules, the corresponding parameters to fill in. Add the following code before?>
mysql_connect ("localhost", "root", "" "); mysql_select_db (" PC "); mysql_query (" Set names ' UTF8 ' "); for ($i =0; $i <count ( $arr) $i + +) {$id = $arr [$i][0]; $title = $arr [$i][1]; $content = $arr [$i][2]; $link = $arr [$i][3]; $time =strtotime ($arr [$i] [4]); $views =rand (100,10000); mysql_query ("INSERT into ' v9_news ' (' id ', ' catid ', ' typeid ', ' title ', ' style ', ' thumb ', ' Keywords ', ' description ', ' posids ', ' url ', ' Listorder ', ' status ', ' Sysadd ', ' islink ', ' username ', ' inputtime ', ' UpdateTime ') VALUES (' $id ', 6, 0, ' $title ', ', ', ', ', ', ' 0, ' $link ', 0, Phpcms, 1, 0, ' mysql_qu ', ' $time ', ' $time ') ') Ery (' INSERT into ' v9_news_data ' (' id ', ' content ', ' readpoint ', ' groupids_view ', ' paginationtype ', ' maxcharperpage ', ' Template ', ' paytype ', ' relation ', ' Voteid ', ' allow_comment ', ' CopyFrom ') VALUES (' $id ', ' $content ', 0, ' ', 0, 10000, ', 0, ", 0, 1, ' | ')"); mysql_query ("INSERT into ' v9_hits ' (' hitsid ', ' catid ', ' views ', ' yesterdayviews ', ' dayviews ', ' Weekview S ', ' monthviews ', ' UpdateTime ') VALUES (' c-1-$id ', ' 6 ', ' $views ',0, 0, 0, 0, ' $time ');}
PHPCMS database storage rules, I have in another article detailed analysis, see PHPCMS Database storage Module Production Tutorial
There is a CATID field above, my default classification is ID6, I modify it according to my own situation. Finally entered the phpcms backstage, the URL rules changed to the original WordPress in the same fixed link is completed.
Welcome reprint, but please keep the original address http://www.sjyhome.com/php/wp-to-pc-sql.html
"Go" WordPress to phpcms Strategy-database Perfect conversion