If you use
$page->children() in ProcessWire it will only get direct descendents. If you want all descendents you don’t need to interate through all children, grandchildren, etc. Like
$page has a
find() function. So, all you need to do is something like this:
This will get all descendents that have the template “page”. Obviously, you should change the selector to suit your use case.