Show children pages from parent site


#1

Hallo,
i’m looking for solution to show list of another children pages from parent site.

I can’t do it…


#2

I don’t really understand what you mean, I’m afraid. Could you provide more detail or show your structure and what you want to grab. where.


#3

I have pages

  • home
  • article
    ** article 1
    ** article 2
    ** article 3
    ** article 4
  • contact

And when i will in article > article 2, i would like to show all off others articles pages


#4

You can fetch those siblings with the siblings() method:

$siblings = $page->siblings(false)

The false parameter means, that the page itself is not included.

https://getkirby.com/docs/cheatsheet/page/siblings


#5
<?php foreach($page->parent()->children()->visible() as $item): ?>
    <li><a href="<?= $item->url() ?>" class="d-block text-center text-lg-left px-3 py-3 innymodel"><?php echo $item->title() ?></a></li>
<?php endforeach ?>

Thank you, i wrote some like this, but can I hide current active page? I can use css but i won’t


#6

Not parent, siblings…

<?php foreach($page->siblings(false)->visible() as $item): ?>
    <li><a href="<?= $item->url() ?>" class="d-block text-center text-lg-left px-3 py-3 innymodel"><?php echo $item->title() ?></a></li>
<?php endforeach ?>

Siblings are the pages that are on the same level in the same parent folder, thinks of them as sisters and brothers of the current page.


#7

I understand, I have to thank you. This cms is great


#8

Sorry, I thought it wasn’t quite clear because you posted your original code again. With your original code, you would have achieved the same by excluding the current page, like so:

<?php foreach($page->parent()->children()->not($page)->visible() as $item): ?>
    <li><a href="<?= $item->url() ?>" class="d-block text-center text-lg-left px-3 py-3 innymodel"><?php echo $item->title() ?></a></li>
<?php endforeach ?>

But getting the siblings is much cleaner, less code… although internally, it does exactly the same :wink:

  public function siblings($self = true) {
    return $self ? $this->parent->children() : $this->parent->children()->not($this);
  }