PHPフォルダをWordPressに移行します
-
29-09-2020 - |
質問
CMSレス、フラットファイルPHPウェブサイトを再設計し、WordPressで開発しています。
既存のWebサイトはデータベースを使用していません。PHPサイト内の1つのディレクトリには100ページを超え、コンテンツをWPにインポートする必要があります。
このディレクトリのカスタムコンテンツタイプを作成しましたが、そのような大規模なフォルダを移行/インポートするためのベストプラクティスやヒントやプラグインがありますか?
解決
各PHPファイルにはページの内容が含まれているとします。PHPページであなたのコンテンツがどのように書かれているかに大きく異なります。
<?php
if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handle\n";
echo "Entries:\n";
/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle))) {
echo "$entry\n";
}
/* This is the WRONG way to loop over the directory. */
while ($entry = readdir($handle)) {
echo "$entry\n";
}
closedir($handle);
}
?>
.
それから各ファイルの内容を取得し、あなたのコンテンツがあるべきパターンを見つけます。PREG_REPLACEでコンテンツを入手して、そのコンテンツにPOSTを追加できます。
// Create post object
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(8,39)
);
// Insert the post into the database
wp_insert_post( $my_post );
.
このスクリプトでwp_load.phpを含めるかrequireを必要としてください。
所属していません wordpress.stackexchange