Is there a simple way to get the root page of a child?
about
contact
design
marketing
information
Maybe something like this:
$page->rootParent('design')->children();
It would first go to about
and then give me an object with the children contact
and information
.
The depth is unknown so I can’t just go 2 steps back or so.
Ideas?
UPDATE
I made it work, kind of. I probably need a recursive function or something if there are not simpler solution. As you can see I hang on a new parent on every new if statement.
<?php if( $p->depth() == 1 && $p->hasChildren() ) : ?>
<?php pattern('site/main/sidebar/children', ['p' => $p->children() ]); ?>
<?php elseif( $p->depth() == 2 && $p->parent()->hasChildren() ) : ?>
<?php pattern('site/main/sidebar/children', ['p' => $p->parent()->children() ]); ?>
<?php elseif( $p->depth() == 3 && $p->parent()->parent()->hasChildren() ) : ?>
<?php pattern('site/main/sidebar/children', ['p' => $p->parent()->parent()->children() ]); ?>
<?php endif; ?>
If I give it some time I will get it to work with a recursive function but what I’m really asking for is a more simple way to do it.