You can use sort the list of child pages based on the custom system field.
Try this..
Code: Select all
{php}
$children = cmsms()->GetHierarchyOperations()->GetChildren($content->Id());
$groups = [];
foreach ($children as $child) {
$system = $child->custom_fields['system']; // Replace 'system' with your custom field name
$groups[$system][] = $child;
}
// Sort the groups based on the system field value
ksort($groups);
foreach ($groups as $system => $group) {
// Display the system name
echo "<h2>$system</h2>";
// Sort the child pages within each group if needed
// Example: Sorting by child page name
usort($group, function($a, $b) {
return strcmp($a->Name(), $b->Name());
});
// Display the child pages within the group
foreach ($group as $child) {
echo $child->Name(); // Example: Displaying the child page name
}
}
{/php}
The custom field 'system' is accessed using $child->custom_fields['system']. Replace 'system' with the name of your custom field. You can modify the sorting logic within the usort() function to sort the child pages within each group based on your requirements by name, date, etc.