Martinus Posted August 22, 2022 Share Posted August 22, 2022 I have this selector: $items = $pages->find("parent=/categories/, sort=title"); foreach($items as $item) { echo <h4><a href=''>" . $item->title . "</a></h4> <ul>" . $item->children->each( "<li><a href='{url}'>{title}</a></li>" ) . "</ul> But, do I need to check with if($item->hasChildren ? Because the IF does not work. Link to comment Share on other sites More sharing options...
3fingers Posted August 22, 2022 Share Posted August 22, 2022 Check this : https://processwire.com/api/ref/page/children/ // Render navigation for all child pages below this one foreach($page->children() as $child) { echo "<li><a href='$child->url'>$child->title</a></li>"; } So in your case: $children = $pages->find("parent=/categories/, sort=title")->children(); foreach($children as $child) { // ... manipulate $child here } 1 Link to comment Share on other sites More sharing options...
Martinus Posted August 22, 2022 Author Share Posted August 22, 2022 I understand if I want to find children of the page I am on I can do that. The API says: // Render navigation for all child pages below this one But in my case I am on one page and finding category pages (elsewhere) - then I display them one by one as $item: foreach($items as $item) { So now I have parent $item-1 and need it's children; I have parent $item-2 and need it's children; etc. $item->children->each( "<li><a href='{url}'>{title}</a></li>" ) works fine.... I think. Link to comment Share on other sites More sharing options...
Gideon So Posted August 23, 2022 Share Posted August 23, 2022 Hi @Martinus 15 hours ago, Martinus said: But, do I need to check with if($item->hasChildren ? Because the IF does not work. No. I don't think you need to check if the page has children. Gideon 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