Now for the tricky bit. I only want to list pages that are set to appear in the menu. Again, I can achieve this, but the problem is that the outer HTML elements (<ul> and <section>) will be displayed regardless.
So, what needs to happen is this logical process:
1. Are there child pages of the current page? If yes, continue.
2. Is there at least one page that is set to show in the menu? If yes, continue.
3. Is this showing in the sidebar (using the parameter when calling the UTD)? If yes, wrap the whole block in <section>.
4. Wrap the list items in the <ul> element.
5. Loop through the child pages, ignoring those that that NOT set to show in the menu. Output each to an <li>.
6. Close the </ul> and </section>.
Here's what I have so far. This is completely functional except that it shows the outer HTML elements regardless.
Code: Select all
global $gCms;
// invoke menu manager
$manager =& $gCms->GetHierarchyManager();
// get the current page name
$thisPage = $gCms->variables['page_name'];
// define a specific page alias or use the current page
if (isset($params['the_page_alias'])) {
$currentNode = &$manager->sureGetNodeByAlias($params['the_page_alias']);
}
else {
$currentNode = &$manager->sureGetNodeByAlias($thisPage);
}
// get the list of child pages
$nodes = $currentNode->getChildren();
// if there are children...
if ( $currentNode->hasChildren() ) {
// is this showing in the sidebar?
if (isset($params['sidebar'])) {
if ($params['sidebar'] == 'yes') {
echo '<section id="subpages">';
$sidebar_end = '</section>';
}
}
// redefine or hide the default list title
if (isset($params['title'])) {
if ($params['title'] !== '') {
echo '<h3>'.$params['title'].'</h3>';
}
else { /* do nothing */ }
}
else {
echo '<h3>Pages in this section:</h3>';
}
// set a class name for the list
if (isset($params['class'])) {
if ($params['class'] !== '') {
echo '<ul class="'.$params['class'].'">';
}
else { /* do nothing */ }
}
else {
echo '<ul>';
}
// show each item in a list format
foreach ($nodes as $node) {
$content= $node->getContent();
$url = $content->GetURL();
// hide section header pages
if ($url == "#") {
$url = "index.php?page=".$content->Alias();
}
echo "<li><a href=\"".$url."\">".$content->MenuText()."</a> </li>";
}
echo "</ul>";
// if it's in the sidebar, close the element
echo $sidebar_end;
}