Home » Documentation » $Content->children()

$Content->children()

Returns a stack of content objects that have been added as children to $Content.

To list the children of a piece of content:

// list them all at once
$content->children()->output();

// list one at a time
while ($child = $content->children()->getNext()) { 
  $child->output();
}

By default, children includes the 20 most recently added children objects. You can change this by passing in a count to the first call to this function.

// lets get 500 children!
$content->children(500)->output();

To add a piece of content as a child to another document, set it's parentId field.

// create a new piece of content
$new_content = $POD->getContent();
$new_content->set('headline','new child document');
$new_content->set('type','post');

// set its parentId and save it
$new_content->set('parentId',$content->get('id'));
$new_content->save();

// now we can use the parent and children functions

$new_content->parent()->write('headline');

$content->children()->output();

Of note: The children stack does not automatically reload when you add a new child. If you have already loaded it once, you will have to force a reload by using the $Stack->fill() function:

// load and display all the children
$parent->children()->output();

// now create a new child
$new_child->set('parentId',$parent->get('id'));
$new_child->save();

// now we need to reload children
$parent->children()->fill();
  • Discuss This Document

No comments have been posted yet.

Download Download the latest version of PeoplePods!

0.7 Latest Version:
Release Notes

A free membership is required to download PeoplePods.

  Already Registered? Login

Recent Posts from Our Blog

Developer Preview Launch!

I am very excited to announce the launch of PeoplePods version 0.666, THE DEVELOPER PREVIEW! After tons of hacking, I have tweaked the last line of code, and I am finally ready for a wider audience...