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

Menu like this!

Feed 7 posts, 2 voices

Avatar
11 posts

Hi, thank´s for a really good tool.

I need some help when developing a site, it´s about a menu.
What I want is like This

I found this PHP in here But it not do the jobb all the way. ;)

<?php

function stackup($page, $level, &$astack)
  {
  $ancestor = $page->parent;
  if ($ancestor)
    {
    $astack[$level + 1] = $ancestor;
    stackup($ancestor, $level + 1, $astack);
    }
  }

function unstack($current, $max, $stack)
  {
  $here = $stack[$current];
  $next = $stack[$current + 1];
  $childs = $here->children();
  $count = count($childs);
  if ($count > 0)
    {
    echo '<ul>'."\n";
    foreach ($childs as $child)
      {
      if ($child->breadcrumb == $next->breadcrumb)
        { if ($current == $max - 1) { $class = 'class="current"'; } else { $class = ''; }
        echo '<li>'.$child->link('', $class)."\n";
        if ($current < $max) {
          unstack($current + 1, $max, $stack);
          echo '</li>'."\n";
          }
        else echo '<li>'.$child->link().'</li>'."\n";
        }
      else echo '<li>'.$child->link().'</li>'."\n";
      }
    echo '</ul>'."\n";
    }
  }

$astack[0] = $this;
stackup($this, 0, $astack);
$bstack = array_reverse($astack);
$lev = count($bstack) - 1;
if ($lev == 0) echo '<ul><li>'.$bstack[0]->link('', 'class="current"')."\n";
else echo '<ul><li>'.$bstack[0]->link()."\n";
unstack(0, $lev, $bstack);
echo '</li></ul>'."\n";
?>
 
Avatar
1493 posts

Hi jelm! Glad you like it so far.

The “problem” for your purposes with that (great!) “stacking” navigation system is that it produces nested lists, of course. You need something that produces a discrete list for each level of navigation.

I have been working on this, and have something that more-or-less works. It does not work for “Articles”/blog-type entries, but it works fine for “ordinary” pages and subpages. I have a test demo set up here if you want to take a look. (That link takes you to a page fairly deep into the menu system.)

If it looks promising, I can always share the code.

Or maybe others have a better “discrete list” menu system working…??

 
Avatar
11 posts

Hi, I would like to take part of that code.
Are you share it here or by mail ?
Thanks David.

 
Avatar
1493 posts

Hi again jelm:

You can grab the code (EXACTLY as it is from that test site!) from the Frog Pastebin. Notes:

  • You many not need the depth of menus if you don’t need “child-of-child-of-child-of-child-of-child-of-home” (that is, five levels!) as in that code: you can just delete what you don’t need.
  • There is a very basic way of handling archive/blog pages so the system doesn’t throw an error. If you aren’t using “archive”/news/blog pages, then that can be ignored.
  • You should save that code in a snippet (I called mine “multiNav”) and call it in your Layout like this:
<?php $this->includeSnippet('multiNav'); ?>
  • You will need to work up the CSS for those independent UL lists, of course! :)

Hope that helps!

 
Avatar
11 posts

Great, the Css part I can handle ;)

Thanks David.

 
Avatar
11 posts

My php skills are really bad, so in my new produkt I need to tweek this code!

Is there a way of show all links directly so I can use jquery to show and hide the different list without to reload the page.

thx

 
Avatar
11 posts

My php skills are really bad, so in my new produkt I need to tweek this code!

Is there a way of show all links directly so I can use jquery to show and hide the different list without to reload the page.

And here is the code that needs some tweek!

<?php $article = $this->find('articles'); ?>
<?php $archives = $article->archive->archivesByMonth(); ?>
<div id="level1nav">
<ul>

<?php foreach($this->find('/')->children() as $menu): ?>
      <li><?php echo $menu->link($menu->title, (in_array($menu->slug, explode('/', $this->url)) ? ' class="current"': null)); ?></li>
<?php endforeach; ?> 
    </ul>

</div>

<?php
// Navigation for level 2 needs to start at level 1
switch($this->level()) {
  case '1': $level2nav = $this->slug; break;
  case '2': $level2nav = $this->parent->slug; break;
  case '3': $level2nav = $this->parent->parent->slug; break;
  case '4': $level2nav = $this->parent->parent->parent->slug; break;
  case '5': $level2nav = $this->parent->parent->parent->parent->slug; break;
  case '6': $level2nav = $this->parent->parent->parent->parent->parent->slug; break;
  default: $level2nav = '';
  } 
?>
<div id="whiteLine"></div>
<div id="level2nav">
<?php if ($level2nav != '' && $level2nav != 'articles') : ?>

<ul>
<?php foreach ($this->find($level2nav)->children() as $L2Nchild): ?>
    <li><?php echo $L2Nchild->link($L2Nchild->title, (url_start_with($L2Nchild->url) ? ' class="current"': null)); ?></li>
 <!--<li><a href="<?php echo $L2Nchild->url(); ?>"><img border="0" src="<?php echo URL_PUBLIC; ?>public/images/<?php echo $L2Nchild->slug(); ?>.png" alt="<?php echo $menu->title(); ?>" class="menup" /></a></li> -->
<?php endforeach; ?></ul>
<?php endif; ?>

<?php if ($level2nav == 'articles') : ?>
<ul>
<?php foreach ($archives as $date): ?>
  <li><a href="<?php echo BASE_URL . $this->url .'/'. $date . URL_SUFFIX; ?>"><?php echo strftime('%B %Y', strtotime(strtr($date, '/', '-'))); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>

<?php
// Navigation for level 3 needs to start at level 2
switch($this->level()) {
  case '2': $level3nav = $this->slug; break;
  case '3': $level3nav = $this->parent->slug; break;
  case '4': $level3nav = $this->parent->parent->slug; break;
  case '5': $level3nav = $this->parent->parent->parent->slug; break;
  case '6': $level3nav = $this->parent->parent->parent->parent->slug; break;
  default: $level3nav = '';
  } 
?>

<?php
// Navigation for level 4 needs to start at level 3
switch($this->level()) {
  case '3': $level4nav = $this->slug; break;
  case '4': $level4nav = $this->parent->slug; break;
  case '5': $level4nav = $this->parent->parent->slug; break;
  case '6': $level4nav = $this->parent->parent->parent->slug; break;
  default: $level4nav = '';
  } 
?>

<div id="level3nav">
<?php if ($level3nav != '') : ?>
<ul>
<?php foreach ($this->find($level2nav.'/'.$level3nav)->children() as $L3Nchild): ?>
    <li><?php echo $L3Nchild->link($L3Nchild->title, (url_start_with($L3Nchild->url) ? ' class="current"': null)); ?>
    	<?php if (url_start_with($L3Nchild->url)) : ?>
    		<div id="level4nav">
				<?php if ($level4nav != '') : ?>
				<ul>
				<?php foreach ($this->find($level2nav.'/'.$level3nav.'/'.$level4nav)->children() as $L4Nchild): ?>
    				<li><?php echo $L4Nchild->link($L4Nchild->title, (url_start_with($L4Nchild->url) ? ' class="current"': null)); ?></li>
				<?php endforeach; ?></ul>
				<?php endif; ?>
			</div>
		<?php endif; ?>
    </li>
<?php endforeach; ?></ul>
<?php endif; ?>p.
 
Avatar
11 posts

Is there anyone who can help me with this ?