Hey here is my HTML unsorted list with page levels snippet based on the code of the sitemap snippet.
If you think it is good, maybee you will add the functionality to the base snippet:
<?php
$startid = (isset($startid)) ? $startid : 0;
$excludeTemplates = (isset($excludeTemplates)) ? $excludeTemplates : array();
$docs = getDocsWithLevels($modx,$startid);
#var_dump($docs);
// get all templates
$select = $modx->db->select("id, templatename", $modx->getFullTableName('site_templates'));
while ($query = $modx->db->getRow($select)) {
$allTemplates[$query['id']] = $query['templatename'];
}
$remainingTemplates = $allTemplates;
// get templates to exclude, and remove them from the all templates list
if (!empty ($excludeTemplates)) {
$excludeTemplates = explode(",", $excludeTemplates);
// Loop through each template we want to exclude
foreach ($excludeTemplates as $template) {
$template = trim($template);
// If it's numeric, assume it's an ID, and remove directly from the $allTemplates array
if (is_numeric($template) && isset($remainingTemplates[$template])) {
unset($remainingTemplates[$template]);
} else if (trim($template) && in_array($template, $remainingTemplates)) { // If it's text, and not empty, assume it's a template name
unset($remainingTemplates[array_search($template, $remainingTemplates)]);
}
} // end foreach
}
$output .= "<ul class=\"sitemap\">\n";
// TODO: Sort the array on Menu Index
// TODO: Make a nested ul-li based on the levels in the document tree.
foreach ($docs[$startid] as $doc)
{
if (isset($remainingTemplates[$doc['template']]) && $doc['template']!=0)
{
$output .= " <li class=\"sitemap\">";
$output .= "<a href=\"[(site_url)][~" . $doc['id'] . "~]\" class=\"sitemap\">" . $doc['pagetitle'] . "</a>";
$output .= "</li>\n";
$id = $doc['id'];
if(isset($docs[$id])) {
$output .= "<ul class=\"sitemap\">\n";
foreach($docs[$id] as $sub_doc) {
$output .= " <li class=\"sitemap\">";
$output .= "<a href=\"[(site_url)][~" . $sub_doc['id'] . "~]\" class=\"sitemap\">" . $sub_doc['pagetitle'] . "</a>";
$output .= "</li>\n";
}
$output .= "</ul>\n";
}
}
} // end foreach
$output .= "</ul>\n";
return $output;
function getDocsWithLevels($modx,$startid)
{
// get children documents
$docs[$startid] = $modx->getActiveChildren($startid,'menuindex','asc','id,editedon,template,published,searchable,pagetitle,type');
// add sub-children to the list
foreach ($docs[$startid] as $doc)
{
$id = $doc['id'];
if ($modx->getActiveChildren($id))
$docs[$id] = $modx->getActiveChildren($id,'menuindex','asc','id,editedon,template,published,searchable,pagetitle,type');
} // end foreach
return $docs;
}
?>
It will output an unsorted list with the root documents. If there are Child Documents for the Root Document they will be displayed at the same place in a new <ul>
greets moveax1