I’ve been following the doc on generating JSON with Kirby and have been struggling getting it to generate the output – as it is right now, I have it properly outputting all of my top level posts…but i’d love if it also grabbed the children of my one sub-page.
My site is arranged like this– the subpage posts are only shown on the subpage, and the regular posts are shown on the homepage. I’d like the json to be outputted in a similar format…but if not possible, is there a quicker way to change $data = $pages->find('posts')->children()->visible()->flip();
to show just the sub-page posts? I’m not great at this syntax and have been trying variations of $pages ->find(‘feed’)->children and striking out…
Page (Chris)
a. Sub-Page (Feed)
i. sub-page article
ii. sub-page article
iii. sub-page article (x20)
b. Article
c. Article
d. Article (x2)
This is what I’ve got right now:
<?php
header('Content-type: application/json; charset=utf-8');
$data = $pages->find('posts')->children()->visible()->flip();
$json = array();
foreach ($data as $article) {
$json[] = array(
'url' => (string)$article->url(),
'title' => (string)$article->title(),
'date' => (string)$article->date(),
'categories' => (array)$article->categories()->split(),
);
}
echo json_encode($json, JSON_PRETTY_PRINT);