How to show all content from different subfolders on main page

Hey, welcome to our forum!

That is definitely possible, but the code you need depends on how you want to show that content on the main page and on the data model (i.e. what fields are used in each of these pages) of each of these pages.

For example, if you just want to get a long list of all these pages with their titles, you would loop through the index:

<?php
foreach ( $site->index()->listed() as $p ) {
  echo $p->title();
}

Or maybe you want to create different sections per parent page, then you can fetch each of these pages individually:

<?php if ( $recipes = page('recipes') ) : ?>
  <section>
  <h1><?= $recipes->title() ?></h1>
    <?php if ( $recipes->hasListedChildren() ) : ?>
      <ul>
      <?php foreach ( $recipes->children()->listed() as $recipe ) : ?>
        <li>
          <?= $recipe->title()->html() ?>
          <!-- more fields here -->
        </li>
      <?php endforeach ?>
      </ul>
    <?php endif ?>
  </section>
<?php endif ?>

And in the same way for each other page and its children you want to show.


So we could better help you if you provide more detailed information about what exactly you want to achieve. What fields these pages have etc.
1 Like