getformwork / formwork

🏗 A flat file-based Content Management System (CMS) to build and manage sites with simplicity
MIT License
52 stars 12 forks source link

get children/descendants pages from specific page ?? #373

Closed DarkLite25 closed 2 years ago

DarkLite25 commented 2 years ago

how we can get children/descendants pages from specific page and display it ??

giuscris commented 2 years ago

You could use $site->findPage() to get the page wanted and then use the children() method, like this:

$site->findPage('route/to/specific/page')->children();

Then you can display children pages with a foreach loop:

<?php foreach ($site->findPage('route/to/specific/page')->children() as $childPage): ?>
<article>
    <h1><a href="<?= $childPage->uri() ?>"><?= $childPage->title() ?></a></h1>
    <?= $childPage->content() ?>
</article>
<?php endforeach; ?>

I hope you find this information useful.

DarkLite25 commented 2 years ago

thanks it worked