18 posts
|
I’m using the Unlimited levels and children menu from the navigation cookbook and it doesn’t work too well.
It doesn’t end any but the very first menu item with </li>. All following items remain open. Here’s how it looks like:
<ul>
<li>item 1</li>
<li>item 2
<li>item 3
<ul>
<li>subitem 1
</ul>
<li>item 4
</ul>
My navigation snippet looks like this right now:
<?php
function displayChildren($page, $current, $startmenu = true, $limits = null) {
if ($limits != null && array_key_exists($page->slug, $limits)) {
$arr = array('order' => 'position ASC, published_on DESC', 'limit' => $limits[$page->slug]);
} else
$arr = array('order' => 'position ASC, published_on DESC');
if ($page && count($page->children()) > 0) {
echo ($startmenu) ? '<ul>' : '';
foreach($page->children($arr) as $menu) :
echo '<li'.(in_array($menu->slug, explode('/', $current->url)) ? ' class="current"': null).'>'.$menu->link($menu->title);
displayChildren($menu, $current, true, $limits).'</li>';
endforeach;
echo ($startmenu) ? '</ul>' : '';
}
}
?>
<div id="nav">
<?php
$page = $this->find('/');
echo '<ul>';
echo '<li'.(in_array($page->slug, explode('/', $this->url)) ? ' class="current"': null).'>'.$page->link($page->title).'</li>';
echo displayChildren($page, $this, false, array('obvestila' => '3', 'a-sub-page' => '1'));
echo '</ul>';
?>
</div>
|
18 posts
|
Update:
There’s clearly a bug in the code here: Unlimited levels and children
The code should read as follows:
<?php
function displayChildren($page, $current, $startmenu = true, $limits = null) {
if ($limits != null && array_key_exists($page->slug, $limits)) {
$arr = array('order' => 'position ASC, published_on DESC', 'limit' => $limits[$page->slug]);
} else
$arr = array('order' => 'position ASC, published_on DESC');
if ($page && count($page->children()) > 0) {
echo ($startmenu) ? '<ul class="sidemenu">' : '';
foreach($page->children($arr) as $menu) :
echo '<li'.(in_array($menu->slug, explode('/', $current->url)) ? ' class="current"': null).'>'.$menu->link($menu->title);
displayChildren($menu, $current, true, $limits);
echo '</li>';
endforeach;
echo ($startmenu) ? '</ul>' : '';
}
}
?>
Whoever can edit the documentation should fix it. |
1493 posts
|
Got it – thanks! |