FORUMS CLOSED DUE TO SPAM. YOU STILL CAN ADD POST!

Getting rid of undeeded tags

Feed 0 posts, 1 voices

Avatar
26 posts

Hi people,

currently I use this navigation menu:

<?php $subPageId = explode('/', $_SERVER['REQUEST_URI']); $level2=$subPageId[1]; $level3=$subPageId[2]; ?>
<ul>
<li<?php echo url_match('/') ? ' id="current"': ''; ?>><a href="<?php echo URL_PUBLIC; ?>">Home</a></li>    
<?php foreach($this->find('/')->children() as $menu): ?>
<li<?php echo in_array($menu->slug, explode('/', $this->url)) ? ' id="current"': null; ?>>
<?php echo $menu->link($menu->title); ?>
<?php if ($level3 != '') {$item2 = $level2;} else {$item2 = substr($level2,0,-5);} ?>
<?php if ($level2 != '') : ?>
<?php $page2 = $this->find($item2); ?>
<?php if (strpos($_SERVER['REQUEST_URI'],$menu->slug) == true) : ?>
<ul>
<?php foreach ($page2->children(array()) as $menu2): ?>
<li><?php echo $menu2->link(); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
<li><a href="<?php echo URL_PUBLIC; ?>rss.xml" title="KUBES RSS feed">RSS feed</a></li>
</ul>
<?php echo PHP_EOL; ?>

It works allmost perfect!
To bad it does generate two uneeded and invalid <ul></ul> tags when a menu item does not contain a submenu.
How do I get rid of those undeeded tags when there’s just a single menu link?