Martinus Posted November 3, 2022 Share Posted November 3, 2022 Hi all, I am experimenting on a new site. My page structure: - root / company (rootparent) / north / simple / product - root / company (rootparent) / south / advanced / product template names: - home / company / location / category / product When I am on a product-index page, I retrieve all products going after the template 'product'. I also want the product parents (recursive), AND for only 2 levels. Is this possible with the following code from the docs? foreach($product->parents(true) as $parent) { echo "<li><a href='$parent->url'>$parent->title</a></li>"; } I have also found this code which seems to limit results until the one I use as selector. But that one does not work recursive: $items = $product->parentsUntil('template=company'); foreach($items as $item) { echo $item->name; } Any help is appreciated. Link to comment Share on other sites More sharing options...
Robin S Posted November 3, 2022 Share Posted November 3, 2022 You could just use ->parent twice: $parent = $page->parent; $grandparent = $parent->parent; 1 Link to comment Share on other sites More sharing options...
Martinus Posted November 3, 2022 Author Share Posted November 3, 2022 1 hour ago, Robin S said: $parent = $page->parent; $grandparent = $parent->parent; Great! Did not even think about that ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now