protro Posted October 28, 2022 Share Posted October 28, 2022 Hello Processwire peoples. I am a new user and very much enjoying the possibilities afforded by this CMF. I was trying to accomplish $page->children() but exclude returned pages that themselves contained children (I am calling them grandchildren here). I came up with this finally, which seems to work. It excludes the child page that contained children and merges its children with the rest of the original page's children, and sorts in descending chronological order. I am using Rockfrontend and Latte: {var $children = $page->children()->not("children.count>0")} {var $grandChildren = $page->children("children.count>0")->children()} {var $items = $children->append($grandChildren)->sort("-date")} {foreach $items as $item} I find the documentation here a bit confusing. For example I wish I had a list of the system fields belonging to a page. I have trouble locating what the available selectors are. Any help or alternatives much appreciated ? Link to comment Share on other sites More sharing options...
Robin S Posted October 28, 2022 Share Posted October 28, 2022 Welcome @protro ? What you have is fine. This is another way you could do it, which is perhaps a bit more readable: $items = new PageArray(); foreach($page->children as $child) { if($child->hasChildren) { $items->add($child->children); } else { $items->add($child); } } $items->sort('-date'); And if the objective happens to be "I want all the descendants that don't themselves have descendants" then this is potentially quite a bit more efficient because it's only a single DB query: $items = $page->find("children.count=0, sort=-date"); 6 Link to comment Share on other sites More sharing options...
DV-JF Posted October 28, 2022 Share Posted October 28, 2022 4 hours ago, protro said: I find the documentation here a bit confusing. For example I wish I had a list of the system fields belonging to a page. I have trouble locating what the available selectors are. Have a look at the docs, here are two pages I find very helpful. https://processwire.com/api/ref/page/ https://processwire.com/docs/selectors/ Cheer's 2 Link to comment Share on other sites More sharing options...
diogo Posted October 28, 2022 Share Posted October 28, 2022 6 hours ago, Robin S said: And if the objective happens to be "I want all the descendants that don't themselves have descendants" then this is potentially quite a bit more efficient because it's only a single DB query: $items = $page->find("children.count=0, sort=-date"); You can also use the selector with the children() method: $page->children("children.count=0, sort=-date"); 4 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