Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @@Children.php Helper:@@
- <?php
- /**
- * Creates an array with all pages, sub-pages and their respective levels.
- * It can be used to format the list of pages differently in various views.
- *
- * @param string $parent_id - The id of the parent page.
- * @param int $level - The level where to start.
- * @return array The array with all the page objects, with an extra 'level' attribute, informing the page's level.
- */
- function getAllChildren($parent_id=0, $level=0) { // begin method
- $children_array = array();
- if(Page::hasChildren($parent_id)) {
- $pages = Page::childrenOf($parent_id);
- foreach($pages as $child) {
- $child->level = $level;
- $children_array[] = $child;
- $children_array = array_merge($children_array, getAllChildren($child->id, $level+1));
- }
- }
- return $children_array;
- } // End method
- ?>
- @@Listing code as used on "Music" page:@@
- <ul>
- <?php use_helper('Children');
- $allKids = getAllChildren('40');
- foreach ($allKids as $kid) :
- ?>
- <li><?php echo $kid->title() .' ['. $kid->level().']'; ?></li>
- <?php endforeach; ?>
- </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement