I’m re-creating a client’s wordpress site using Kirby. To do this, I’m using (huge) XML files I exported from wordpress, parse them in PHP, and using that data to build the Kirby site’s content folder.
I’m doing this with a PHP script that is outside of any kirby directories - /scripts/parse.php
This is working for the first round, creating pages for each author -
<?php
define('DS', DIRECTORY_SEPARATOR);
// load kirby
require($_SERVER['DOCUMENT_ROOT'] . DS . 'kirby' . DS . 'bootstrap.php');
// all of my XML parsing, builds an $authors[] array
foreach ($authors as $author) {
try {
$newPage = page('writers')->children()->create($uid, 'writer', $writer_arr);
echo "<span style='color:blue'>The page " . $writer_arr['title'] . " has been created</span>";
}
catch(Exception $e) {
echo $e->getMessage();
}
}
The next round is to input all of the data for the books. I tried:
$newPage = page('writers')->children()->find($author_uid)->create($book_uid, 'writer', $book_arr);
But, this won’t work. Trying to do anything with $pages->...
returns an undefined error.
I was able to solve this by creating /content/parse/parse.txt
and moving my script to a parse.php
template. Once I’m working “in” the content, it works as expected.
But, is there a way to dig into this without the PHP being in a template?