3

よし、これが問題だ。以前はワードプレスだったが、70 以上の静的ページに変換されたこのサイトがある。管理者は削除され、サイト全体が静的である (つまり、すべてのページが index.html にある)。作成したい新しいワードプレスのインストールにインポートするだけで済むように、xml を作成するスクリプト。

これまでのところ、XML を作成することはできますが、1 つの投稿しかインポートできません。

データ ソースはページの URL であり、jquery $get を使用して特定のアーカイブの投稿のみをフィルター処理します。

//html
<input type="text" class="full_path">
<input type="button" value="Get Data" class="getdata">

//script

$('.getdata').click(function(){
            $.get($('.full_path').val(), function(data) {
              post = $(data).find('div [style*="width:530px;"]');
              $('.result').html(post.html());

            });
        });//get Data

AJAX を使用して、クリーニングされたデータを以下の php に送信し、XML を作成します。

$file = 'newpost.xml';
$post_data = $_REQUEST['post_data'];
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new post to the file
$catStr = '';
if(isset($post_data['categories']) && count($post_data['categories']) > 0){
    foreach($post_data['categories'] as $category) {
        $catStr .= '<category domain="category" nicename="'.$category.'"><![CDATA['.$category.']]></category>';
    }   
}
$tagStr = '';
if(isset($post_data['tags']) && count($post_data['tags']) > 0){
    //populate post_tag like the above
}
$post_name = str_replace(' ','-',$post_data["title"]);
$post_name = str_replace(array('"','/',':','.',',','[',']','“','”'),'',strtolower($post_name));

$post_date = '2011-4-0'.rand(1, 29).''.rand(1, 12).':'.rand(1, 59).':'.rand(1, 59);
$pubTime = rand(1, 12).':'.rand(1, 59).':'.rand(1, 59).' +0000';

$post = '
    <item>
        <title>'.$post_data["title"].'</title>
        <link>'.$post_data["link"].'</link>
        <pubDate>'.$post_data["date"].' '.$pubTime.'</pubDate>
        <dc:creator>admin</dc:creator>
        <guid isPermaLink="false">http://localhost/saunders/?p=1</guid>
        <description></description>
        <content:encoded><![CDATA['.$post_data["content"].']]></content:encoded>
        <excerpt:encoded><![CDATA[]]></excerpt:encoded>
        <wp:post_id>1</wp:post_id>
        <wp:post_date>'.$post_date.'</wp:post_date>
        <wp:post_date_gmt>'.$post_date.'</wp:post_date_gmt>
        <wp:comment_status>open</wp:comment_status>
        <wp:ping_status>open</wp:ping_status>
        <wp:post_name>'.$post_name.'</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>
        '.$catStr.'
        '.$tagStr.'
        <wp:postmeta>
            <wp:meta_key>_edit_last</wp:meta_key>
            <wp:meta_value><![CDATA[1]]></wp:meta_value>
        </wp:postmeta>
    </item>
';



// Write the contents back to the file with the appended post
file_put_contents($file, $current.$post);

追加した後、以下のコードを追加して xml rss タグを完成させます

</channel>
</rss>

wordpress サイトからエクスポートされた xml ファイルを見て比較すると、ほとんど違いが見られません。助けてください!!

生成された xml のサンプルを次に示します。

<?xml version="1.0" encoding="UTF-8" ?>
<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>lols why</title>
    <link>http://localhost/lols</link>
    <description>Just another WordPress site</description>
    <pubDate>Wed, 03 Oct 2012 04:24:04 +0000</pubDate>
    <language>en-US</language>
    <wp:wxr_version>1.2</wp:wxr_version>
    <wp:base_site_url>http://localhost/lols</wp:base_site_url>
    <wp:base_blog_url>http://localhost/lols</wp:base_blog_url>

    <wp:author><wp:author_id>1</wp:author_id><wp:author_login>adedoy</wp:author_login><wp:author_email>wazzup@gmail.com</wp:author_email><wp:author_display_name><![CDATA[adedoy]]></wp:author_display_name><wp:author_first_name><![CDATA[]]></wp:author_first_name><wp:author_last_name><![CDATA[]]></wp:author_last_name></wp:author>


    <generator>http://wordpress.org/?v=3.4.1</generator>

    <item>
        <title>Sample lift?</title>
        <link>../../breast-lift/delaware-breast-surgery-do-i-need-a-breast-lift/</link>
        <pubDate>Wed, 03 Oct 2012 9:29:16 +0000</pubDate>
        <dc:creator>admin</dc:creator>
        <guid isPermaLink="false">http://localhost/lols/?p=1</guid>
        <description></description>
        <content:encoded><![CDATA[<p>sample</p>]]></content:encoded>
        <excerpt:encoded><![CDATA[]]></excerpt:encoded>
        <wp:post_id>1</wp:post_id>
        <wp:post_date>2011-4-0132:45:4</wp:post_date>
        <wp:post_date_gmt>2011-4-0132:45:4</wp:post_date_gmt>
        <wp:comment_status>open</wp:comment_status>
        <wp:ping_status>open</wp:ping_status>
        <wp:post_name>sample-lift?</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>
        <category domain="category" nicename="Sample Lift"><![CDATA[Sample Lift]]></category><category domain="category" nicename="Sample Procedures"><![CDATA[Yeah Procedures]]></category>
        <category domain="post_tag" nicename="delaware"><![CDATA[delaware]]></category>
        <wp:postmeta>
            <wp:meta_key>_edit_last</wp:meta_key>
            <wp:meta_value><![CDATA[1]]></wp:meta_value>
        </wp:postmeta>
    </item>
    <item>
        <title>lalalalalala</title>
        <link>../../administrative-tips-for-surgery/delaware-cosmetic-surgery-a-better-experience/</link>
        <pubDate>Wed, 03 Oct 2012 3:20:43 +0000</pubDate>
        <dc:creator>admin</dc:creator>
        <guid isPermaLink="false">http://localhost/lols/?p=1</guid>
        <description></description>
        <content:encoded><![CDATA[
                lalalalalala
            ]]></content:encoded>
        <excerpt:encoded><![CDATA[]]></excerpt:encoded>
        <wp:post_id>1</wp:post_id>
        <wp:post_date>2011-4-0124:39:30</wp:post_date>
        <wp:post_date_gmt>2011-4-0124:39:30</wp:post_date_gmt>
        <wp:comment_status>open</wp:comment_status>
        <wp:ping_status>open</wp:ping_status>
        <wp:post_name>lalalalalala</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>
        <category domain="category" nicename="lalalalalala"><![CDATA[lalalalalala]]></category>
        <category domain="post_tag" nicename="oink"><![CDATA[oink]]></category>
        <wp:postmeta>
            <wp:meta_key>_edit_last</wp:meta_key>
            <wp:meta_value><![CDATA[1]]></wp:meta_value>
        </wp:postmeta>
    </item>
</channel>
</rss>

何が足りないのか教えてください....

4

4 に答える 4

2

さて、再ハッシュして私があなたを理解していることを確認するために、これはあなたの静的ファイルからワードプレスに戻る試みです。

これを行うには、RSSフィード(X)HTML、および静的ページからのインポートに関して、WPコーデックスで概説されている3つの主要な方法があります。そうは言っても、整形式のHTMLを使用している場合、JQuery検索文字列から実行するように見える最も簡単な方法の1つはコーデックスで参照されているHTMLImport2プラグインを使用することです。これは、ディレクトリ、URLからこれを実行し、新しいインストールの管理画面から検索パラメータを指定するためのいくつかのオプションを提供します。

これがうまくいかない場合、またはインポートのためにすべてのページをXMLに変換したい場合は、既にPHPを使用してXMLを生成しているため、PHP DOMライブラリを使用して開き、解析し、抽出し、静的ファイルからデータを書き込みます。これにより、サイト全体を閲覧してXMLを生成する時間を節約でき、すべてのページのXMLファイル全体を一挙に作成できます。

いずれにせよ、WordPressのカスタム形式を再作成するのではなく、プレーンなRSSファイルを使用することをお勧めします。これは、適切に行われると、すべてのコンテンツタイプのデータベース参照(マップIDなど)が多数あるためです。必要ないようですので、最低限必要なものを最小限に抑えた通常のRSSファイルを作成してみてください。コーデックスを使用してインポートした後、必要に応じてそれらの投稿を編集して作成者などを再割り当てできます。RSSフィードからインポートするための指示。それははるかに簡単になります。

于 2012-10-08T16:22:00.783 に答える
2

私もあなたと同じようなケースでした。投稿用のデータと注目の画像が入力された xml エクスポート ファイルを生成したいと考えていました。

これが私がしたことです:

  1. ローカルホストに Wordpress をインストールする
  2. WordPressで設定したデフォルトのページとコメントを削除する
  3. 投稿のタイトル、コンテンツなどを変更します (省略可能です。エクスポートされた xml ファイルでこれらの情報を見つけやすくするためにこれを行いました)
  4. wordpress インポーター プラグインをインストールして有効化する
  5. ツールを使用してエクスポートする
  6. xmlファイルを見てください

ここに私のxmlファイルがあります:

<?xml version="1.0" encoding="UTF-8" ?>
<!-- generator="WordPress/3.9" created="2014-04-25 14:19" -->
<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>wordpresslocal title</title>
    <link>http://wordpresslocal</link>
    <description>Another Wordpress Local Blog</description>
    <pubDate>Fri, 25 Apr 2014 14:19:36 +0000</pubDate>
    <language>de-DE</language>
    <wp:wxr_version>1.2</wp:wxr_version>
    <wp:base_site_url>http://wordpresslocal</wp:base_site_url>
    <wp:base_blog_url>http://wordpresslocal</wp:base_blog_url>

    <wp:author><wp:author_id>1</wp:author_id><wp:author_login>wordpresslocaladmin</wp:author_login><wp:author_email>wordpresslocal@einrot.com</wp:author_email><wp:author_display_name><![CDATA[wordpresslocaladmin]]></wp:author_display_name><wp:author_first_name><![CDATA[]]></wp:author_first_name><wp:author_last_name><![CDATA[]]></wp:author_last_name></wp:author>


    <generator>http://wordpress.org/?v=3.9</generator>

    <item>
                <title>POST TITLE</title>
        <link>http://wordpresslocal/post-title</link>
        <pubDate>Fri, 25 Apr 2014 14:02:29 +0000</pubDate>
        <dc:creator><![CDATA[wordpresslocaladmin]]></dc:creator>
        <guid isPermaLink="false">http://wordpresslocal/?p=1</guid>
        <description></description>
        <content:encoded><![CDATA[POST CONTENT]]></content:encoded>
        <excerpt:encoded><![CDATA[]]></excerpt:encoded>
        <wp:post_id>1</wp:post_id>
        <wp:post_date>2014-04-25 14:02:29</wp:post_date>
        <wp:post_date_gmt>2014-04-25 14:02:29</wp:post_date_gmt>
        <wp:comment_status>open</wp:comment_status>
        <wp:ping_status>open</wp:ping_status>
        <wp:post_name>post-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>
        <category domain="category" nicename="category1"><![CDATA[CATEGORY1]]></category>
        <category domain="post_tag" nicename="tag1"><![CDATA[TAG1]]></category>
        <wp:postmeta>
            <wp:meta_key>_thumbnail_id</wp:meta_key>
            <wp:meta_value><![CDATA[6]]></wp:meta_value>
        </wp:postmeta>
    </item>
</channel>
</rss>
于 2014-04-25T18:37:04.303 に答える
1

あなたが持っている

<wp:post_id>1</wp:post_id>

両方の項目で。これは主キーであるため、これが主な問題だと思います。

于 2014-12-16T17:06:54.907 に答える
1

カスタムの WordPress エクスポート/インポート XML は、実際には他のデータベースから作成されたコンテンツで非常にうまく機能します。投稿、ページ、メタデータ、添付ファイル、コメントなどをインポートできました。

しかし、実際にはいくつかの要素でかなりうるさいです.2つの投稿が同じ作成時間を共有している場合、1つだけが挿入され、2番目の投稿は重複していると見なされます(したがって、日付のみのソースにランダムな時間を追加する必要があります)。

あなたのサンプルでは、​​ wp:post_date は日付形式からかけ離れているように見えるため、これが重複検出をトリガーし、単一の投稿がインポートされる理由である可能性があります。

于 2013-07-02T06:13:46.657 に答える