Show promo article on homepage

how can i buid solution, which will let me show one of the articles from all (chosen article), on the home page.
I tried checkbox on the article, and when is checked article shows on the homepage.


  label: Promo
  type: checkbox

On template some like this

<?php foreach($page->find($promo()->bool()) as $article): ?>

But of course does not work

This will get only the first it finds, the result is a single page (then you don’t loop through it with foreach)

$promo = $articles->findBy('promo', true);

or filter, then the result is a collection (use foreach to loop. through the result

$promo = $articles->filterBy('promo', true);

You can use first() on the latter to only get the first.

Ok, thank you, but how can i show data from this article without foreach?
i tried this

<?php foreach ($page->children()->visible()->filterBy('promo',true) as $p): ?>

<?= $p->title() ?>

I forgot, that articles are children sites

You can’t loop through a single page, just echo the content:

$articles = page('blog')->children()->visible();
$promo = $articles->findBy('promo', true);
echo $promo->title();

With filter you get a collection and have to loop through the collection:

$articles = page('blog')->children()->visible();
$promos = $articles->filterBy('promo', true);
foreach($promos as $promo):
  echo $promo->title();

It doesn’t work, meaby i did not describe exactly how structure pages looks like.

  • Home
  • Projects (disable)
    • Child page 1
      • project 1 (promo checkbox - 0)
      • project 1 (promo checkbox - 0)
    • Child page 2
      • project 1 (promo checkbox - 0)
      • project 1 (promo checkbox - 1)
    • Child page 3
      • project 1 (promo checkbox - 0)
    • Child page 4
      • project 1 (promo checkbox - 0)

I have to get data from page where promo checkbox is 1
Now I’m getting all of the children pages, without filtering

Change that to:

$articles = page('projects')->grandChildren()->visible();

I’d recommend you read the docs on how to fetch particular pages and their descendants.