header drop down menu

Feed 1 posts, 2 voices

Avatar
0 posts

Hi there,

I am trying to create a drop down menu for my top navigation… so the child items appear under the parent item. I have set up the CSS, but cannot work out the PHP. This is the header code:

 <div class="menu">
    <ul>
      <li><a<?php echo url_match('/') ? ' class="current"': ''; ?> href="<?php echo URL_PUBLIC; ?>">Home</a></li>
<?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>
 
Avatar
15 posts

Try the following Toolman.

<div class="nav">
    <ul>
      <li><a<?php echo url_match('/') ? ' class="current"': ''; ?> href="<?php echo URL_PUBLIC; ?>">Home</a></li>
<?php foreach($this->find('/')->children() as $menu): ?>
      <li>
         <?php echo $menu->link($menu->title, (in_array($menu->slug, explode('/', $this->url)) ? ' class="current"': null)); ?>
	 <div class="menu">
		<ul>
		<?php foreach($menu->children() as $child):?>
			<li><?php echo $child->link() ?></li>
		<?php endforeach; ?>
		</ul>
         </div>
      </li>
<?php endforeach; ?> 
    </ul>
  </div> <!-- end #navigation -->

Possibly not the best semantics, but that’s easy enough to alter.