Child Enumeration Plugin

plugins/ChildrenLinkTree.inc

<?php namespace ProcessWire;
/*
 * Module inserts a simple UL list containing links to child pages
 */

class ChildrenLinkTree extends RepeaterFlexItem {
	public static function getModuleInfo() {
		return array(
			'title' => __('Child Links', __FILE__), // Module Title
			'version' => 1,
			'icon' => 'fa fa-sitemap',
			);
	}

	public static function getFields() { return [ ]; }	// No fields!
	private function renderChildTree(&$out, Page $page) {	// Traverse whole child tree
		// We are using a reference to the $out buffer to avoid copying the whole markup multiple times!
		if($page->hasChildren())
			{
			$out .= '<ul>';		// Begin our list
			foreach($page->children as $pg)	// Enumerate any child page
				{
				$out .= "<li><a href='{$pg->url}'>{$pg->title}</a>";
				$this->renderChildTree($out, $pg);
				$out .= "</li>";
				}
			$out .= '</ul>';	// Terminate our list
			}
	}
	public function render(Page $pg) {
		$out = '';
		$this->renderChildTree($out, wire('page'));	// Render all children from "current" page
		return($out);
	}
}

This tiny plugin generates the link lists on the root pages for documentation and demos. It does not provide any data input and simply enumerates all children and adds a link for each.

prepared in 78ms (content 33ms, header 0ms, Menu 27ms, Footer 16ms)