Reference direct page child, but globally?

I have a “Work” parent page, and then “Projects” as children. In each project I can add a “Quote.” In the parent Work page I load in a random Quote pulled from all the published quote blocks.

Is there a way for me to do the same thing on another page entirely? The way I’m doing it now only works on the direct parent:

<?php foreach ($page->children()->children()->shuffle()->filterBy('quoteToggle', 'true', ',' )->limit(1) as $featuredQuote): ?>

I want to be on another page entirely and do the same thing. “Load in a random quote from any of the published quote blocks in project pages.”

So the quotes are children of a project?

You can fetch any page from anywhere using the page() helper. It expects the path to the page as argument.

page('work')->grandchildren()->shuffle()->filterBy('quoteToggle', 'true', ',' )->limit(1)
1 Like

From the docs (

the $page variable always refers to the current page. However, you can also define a $page object by calling a specific page using the page() helper:

$page = page('somepage');

1 Like

It’s been over a year since you helped me last, and I can confidently say my love for you has only increased. Good grief I had no idea you could reference a page by name, and I also appreciate you slipping in the “grandchildren” goodness, which I also had no idea existed.

Thank you!

1 Like