evanmcd Posted January 17, 2013 Share Posted January 17, 2013 Hi, I'm having the strangest problem, that I'm guessing someone will look at and figure out in two seconds. It's been that kind of day... I'm simply trying to loop through the children of a page using the code below: $my_page = $pages->get("/my-page/"); echo('<p>$my_page->numChildren: ' . $my_page->numChildren . '</p>'); // 84 $my_children = $my_page->children; echo('<p>count($my_children): ' . count($my_children) . '</p>'); // 0 foreach($my_children as $child) { echo('<p>Looping on $child</p>'); // never displayed } What I'm getting is not making sense... why would numChildren return the correct number of children of the page, but $page->children wouldn't? Thanks. 1 Link to comment Share on other sites More sharing options...
Soma Posted January 17, 2013 Share Posted January 17, 2013 *ZENSORED* completely missed it once more Link to comment Share on other sites More sharing options...
Soma Posted January 17, 2013 Share Posted January 17, 2013 Sorry . Damn mobile reading i missed it. Ok but the answer to your problem is: You have to write children() as it's a method not a property. Some other API can be used both with and without so but in this case i think it doesnt. Maybe still something for Ryan to change in case it's this. Damn again, I shouldn't call from memory when having sleep loss. I think Wanze has a good point below 2 Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 17, 2013 Share Posted January 17, 2013 (edited) On 18.1.2013 at 0:33 AM, evanmcd said: It's been that kind of day... [removed spam image] Edited April 5, 2017 by LostKobrakai Seems like that image host is no longer hosting it's original images 1 Link to comment Share on other sites More sharing options...
Wanze Posted January 17, 2013 Share Posted January 17, 2013 $my_page->numChildren does also count hidden (maybe unpublished) pages, while $my_page->children does not include them by default. If you use count($my_page->children("include=hidden")), it's the same number Edit: Too late again 4 Link to comment Share on other sites More sharing options...
evanmcd Posted January 18, 2013 Author Share Posted January 18, 2013 Oh, of course, the children are all unpublished. "Why couldn't you easily tell that they were unpublished by the strikethrough" you ask? Because I'm using a slightly modified version of @Soma's nice PageListImageLabel module that has images shown as dimmed when they are published but fully opaque when they are unpublished (for moderation of the images). Thanks @Wanze and everyone for the help. Oh, and of course special thanks to @Adamkiss for the "hug". Those guys are only slightly balder than I am 2 Link to comment Share on other sites More sharing options...
Soma Posted January 18, 2013 Share Posted January 18, 2013 Never too late Wanze! Corrected my post above... need some sleep too Link to comment Share on other sites More sharing options...
bernhard Posted February 4, 2015 Share Posted February 4, 2015 i think this shoud find its way into the docs - no word about that: https://processwire.com/api/variables/page/ but how? stumbled over this today and once more found the answer quickly in the forum but anyway, i'm sure there are others not knowing about this different behaviour of counting children... 1 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