Rewish

WordPressへ移行するならXMLを書き出すのがスムーズ

WordPressに限った話では無いですが、移行用のエクスポートファイルは移行先のツールに合わせたフォーマットの方が良いんじゃないかと言うお話。

ブログツールによっては、各種ブログのエクスポートフォーマットに合わせたインポート機能がついていたりしますが、結局は他所様の作ったツールなので対応が微妙だったりしますよね。

その点、今回提案する方法なら、割とスムーズにインポート出来るんじゃないかなと思います。

※今回はMTからの移行を例に説明していますが、他のブログサービスやブログツールでも、なんらかの方法で書き出しが可能ならばいけると思います。

経緯

先日、このブログもMTからWordPressに移行しましたが、WordPressのMTフォーマットでのインポート機能もかなり微妙でした。と言うか使い物にならない。

そんなWordPressも 自分のことなら出来るだろう と言う考えからWordPressのフォーマットに合わせて書き出してみました。

テンプレートを作成

wp_export.xmlなど適当な名前で以下を書き出す。

<?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>
    <wp:wxr_version>1.0</wp:wxr_version>
<mt:Categories show_empty="1">
    <wp:category><mt:ignore></mt:ignore
        ><wp:category_nicename><$mt:CategoryBasename$></wp:category_nicename><mt:ignore></mt:ignore
        ><wp:category_parent><mt:ParentCategory><$mt:CategoryLabel$></mt:ParentCategory></wp:category_parent><mt:ignore></mt:ignore
        ><wp:cat_name><![CDATA[<$mt:CategoryLabel$>]]></wp:cat_name><mt:ignore></mt:ignore
        ><wp:category_description><![CDATA[<$mt:CategoryDescription$>]]></wp:category_description><mt:ignore></mt:ignore
        ></wp:category>
</mt:Categories>
<mt:Tags>
    <wp:tag><mt:ignore></mt:ignore
        ><wp:tag_slug><$mt:TagName$></wp:tag_slug><mt:ignore></mt:ignore
        ><wp:tag_name><![CDATA[<$mt:TagName$>]]></wp:tag_name><mt:ignore></mt:ignore
    ></wp:tag>
</mt:Tags>
<mt:Entries lastn="0" sort_order="ascend">
    <item>
        <title><$mt:EntryTitle$></title>
        <link><$mt:EntryPermalink$></link>
        <pubDate><$mt:EntryDate format_name="rfc822"$></pubDate>
        <dc:creator><![CDATA[<$mt:EntryAuthor$>]]></dc:creator>
<mt:EntryCategories>
        <category><![CDATA[<$mt:CategoryBasename$>]]></category>
</mt:EntryCategories>
<mt:EntryTags>
        <category domain="tag"><![CDATA[<$mt:TagName$>]]></category>
</mt:EntryTags>
        <guid isPermaLink="false"><$mt:EntryPermalink$></guid>
        <description></description>
        <content:encoded><![CDATA[<$mt:EntryBody$><mt:EntryIfExtended>
<!--more-->
<$mt:EntryMore$></mt:EntryIfExtended>]]></content:encoded>
        <excerpt:encoded><![CDATA[<$mt:EntryExcerpt$>]]></excerpt:encoded>
        <wp:post_id><mt:Ignore><$mt:EntryID$></mt:Ignore></wp:post_id>
        <wp:post_date><$mt:EntryDate format="%Y-%m-%d %H:%M:%S"$></wp:post_date>
        <wp:post_date_gmt><$mt:EntryDate format="%Y-%m-%d %H:%M:%S"$></wp:post_date_gmt>
        <wp:comment_status><mt:IfCommentsAccepted>open<mt:Else>closed</mt:IfCommentsAccepted></wp:comment_status>
        <wp:ping_status><mt:IfPingsAccepted>open<mt:Else>closed</mt:IfPingsAccepted></wp:ping_status>
        <wp:post_name><$mt:EntryBasename$></wp:post_name>
        <wp:status><$mt:EntryStatus lower_case="1"$></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>
<mt:Comments lastn="0">
        <wp:comment>
                <wp:comment_id><$mt:CommentID$></wp:comment_id>
                <wp:comment_author><![CDATA[<$mt:CommentAuthor default="??"$>]]></wp:comment_author>
                <wp:comment_author_email><$mt:CommenterEmail$></wp:comment_author_email>
                <wp:comment_author_url><$mt:CommentURL$></wp:comment_author_url>
                <wp:comment_author_IP><$mt:CommentIP$></wp:comment_author_IP>
                <wp:comment_date><$mt:CommentDate format="%Y-%m-%d %H:%M:%S"$></wp:comment_date>
                <wp:comment_date_gmt><$mt:CommentDate format="%Y-%m-%d %H:%M:%S"$></wp:comment_date_gmt>
                <wp:comment_content><![CDATA[<$mt:CommentBody$>]]></wp:comment_content>
                <wp:comment_approved><mt:IfCommentsActive>1<mt:Else>0</mt:IfCommentsActive></wp:comment_approved>
                <wp:comment_type></wp:comment_type>
                <wp:comment_parent>0</wp:comment_parent>
                <wp:comment_user_id>0</wp:comment_user_id>
        </wp:comment>
</mt:Comments>
<mt:Pings lastn="0">
        <wp:comment>
                <wp:comment_id><$mt:PingID$></wp:comment_id>
                <wp:comment_author><![CDATA[<$mt:PingTitle$>]]></wp:comment_author>
                <wp:comment_author_email></wp:comment_author_email>
                <wp:comment_author_url><$mt:PingURL$></wp:comment_author_url>
                <wp:comment_author_IP><$mt:PingIP$></wp:comment_author_IP>
                <wp:comment_date><$mt:PingDate format="%Y-%m-%d %H:%M:%S"$></wp:comment_date>
                <wp:comment_date_gmt><$mt:PingDate format="%Y-%m-%d %H:%M:%S"$></wp:comment_date_gmt>
                <wp:comment_content><![CDATA[<$mt:PingExcerpt$>]]></wp:comment_content>
                <wp:comment_approved><mt:IfPingsActive>1<mt:Else>0</mt:IfPingsActive></wp:comment_approved>
                <wp:comment_type>trackback</wp:comment_type>
                <wp:comment_parent>0</wp:comment_parent>
                <wp:comment_user_id>0</wp:comment_user_id>
        </wp:comment>
</mt:Pings>
    </item>
</mt:Entries>
</channel>

</rss>

ちょっと長くなったけど、こんな感じでいけると思います。

インポートする

XMLを書き出したら後はインポートするだけですね!

WordPressのインポートは【メニュー】→【ツール】→【インポート】です。

注意点

運用の方法によっては、今回示したコードでは上手くインポート出来ないかもしれません。

例えばカテゴリーベースのURLで複数カテゴリーを指定している場合は、親カテゴリーと言う概念が無いWordPressではURLが変わってしまう可能性があります。

その辺りは適当に調整してみて下さい(そしてアウトプットして下さい)。