kaz Posted October 28, 2022 Share Posted October 28, 2022 I need to list subpages by mengtest and title of a mother page as a simple foreach ul list. Is there a way, similar to a menu, to list child pages? I couldn't find anything about this in the docs. Maybe you can give me a hint what to look for? Link to comment Share on other sites More sharing options...
BitPoet Posted October 28, 2022 Share Posted October 28, 2022 2 hours ago, kaz said: mengtest ? 1 Link to comment Share on other sites More sharing options...
netcarver Posted October 28, 2022 Share Posted October 28, 2022 If you know the parent page you can iterate over all the children very easily, even passing in a selector with your mengtest condition. You could try... echo "<ul>"; foreach($page->children('mengtest=...') as $child) { echo "<li><a href='$child->url'>$child->title</a></li>"; } echo "</ul>"; Docs: https://processwire.com/api/ref/page/children/ 1 Link to comment Share on other sites More sharing options...
Jan Romero Posted October 28, 2022 Share Posted October 28, 2022 I was looking at this thread earlier and was confused, but now I’ve had a drink, I think you want to show a single list of pages whose parent matches some conditions? You can use selectors on fields of the parent like this: pages()->find('parent.title=something, parent.mengtest=orother') Link to comment Share on other sites More sharing options...
kaz Posted October 29, 2022 Author Share Posted October 29, 2022 14 hours ago, BitPoet said: ? sorry, a typing error: mengtest = menutext ('menutext|title') 1 Link to comment Share on other sites More sharing options...
kaz Posted October 29, 2022 Author Share Posted October 29, 2022 @netcarver thanks netcarver, this helped a lot. echo "<ul id='side-menu' class='uk-list uk-margin-remove uk-padding-remove'>"; foreach($pages->get(1044)->children as $child) { $active = wire('page') == $child ? "current" : ""; echo "<li class='$active'><a href='$child->url' title='$child->title'>" . $child->get('menutext|title') . "</a></li>"; } echo "</ul>"; I call the list pages in my base template with the page ID of the parent page: <?php if ($page->id == 1044): ?> <?php include('views/partials/menu-aside.php'); ?> <?php endif; ?> However, the list should also be displayed in all children's pages. ID is therefore wrong? Is there another option which includes the children's sites? Link to comment Share on other sites More sharing options...
netcarver Posted October 29, 2022 Share Posted October 29, 2022 I might be misunderstanding, but couldn't you do this in the base template...? <?php if ($page->id == 1044 || $page->parent->id == 1044): ?> 1 Link to comment Share on other sites More sharing options...
kaz Posted October 29, 2022 Author Share Posted October 29, 2022 1 hour ago, netcarver said: I might be misunderstanding, but couldn't you do this in the base template...? Exactly, that was my goal, to do it in the base template. Thanks that works! 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