How do I only ask for a single child page? I can only find examples to loop through and display all of them. I’d love to say, “Only the page with this tag” or “Only the latest page by publish date.”
<?php foreach($page->children() as $subpage): ?>
<li>
<a href="<?= $subpage->url() ?>">
<?= html($subpage->title()) ?>
</a>
</li>
<?php endforeach ?>
Pretty sure I just figured this out. For anyone else looking, there are a number of filter options:
Ok - I need a nudge here…
This code shows every child of the “Work” page:
<?php if ($projects = page('work')): ?>
<?php foreach ($projects->children()->listed() as $project): ?>
<!-- Stuff here. -->
<?php endforeach ?>
<?php endif ?>
I’m attempting to use the filterBy feature to show only a single child of the Work page, but so far no luck:
<?php if ($projects = page('work')): ?>
<?php foreach ($projects->children()->filterBy('tag', 'featured', ',') as $project): ?>
<!-- Stuff here. -->
<?php endforeach ?>
<?php endif ?>
I figured it out! I had my field named “tags” in my blueprint, but I was trying to filter by ‘tag’.