views:

64

answers:

2

Existing array code:

function get_menu($menu = array(), $ulclass = '', $is_main_menu = false) {
    global $menu_selected;
    $output = '';
    if (empty($menu)) {
     return $output;
    }

    $output .= '<ul' . (!empty($ulclass) ? (' class="' . $ulclass . '"') : '') . '>';
    foreach($menu as $item) {
     if (!$is_main_menu || !isset($item['hide_in_main']) || !$item['hide_in_main']) {
      $li_class = (isset($item['sub']) && !empty($item['href']) ? ('dir') : '');
      if (isset($menu_selected) && !empty($menu_selected) && $menu_selected == $item['href']) {
       $li_class = (!empty($li_class)) ? $li_class . ' selected' : 'selected';
      }
      if (isset($item['li_class']) && !empty($item['li_class'])) {
       $li_class .= (!empty($li_class)) ? ' ' . $item['li_class'] : $item['li_class'];
      }
      $output .= '<li' . (!empty($li_class) ? ' class="' . $li_class . '"': '' ) . '>';
      $output .= '<a';
      if (isset($item['href']) && !empty($item['href'])) {
       $output .= ' href="' . $item['href'] .'"';
      }
      if (isset($item['title']) && !empty($item['title'])) {
       $output .= ' title="' . $item['title'] .'"';
      }
      if (isset($item['class']) && !empty($item['class'])) {
       $output .= ' class="' . $item['class'] .'"';
      }
      if (isset($item['target']) && !empty($item['target'])) {
       $output .= ' target="' . $item['target'] .'"';
      }
      $output .= '>';
      if (isset($item['title']) && !empty($item['title'])) {
       $output .= $item['title'];
      } else if (isset($item['href']) && !empty($item['href'])) {
       $output .= $item['href'];
      }
      $output .= '</a>';
      if (isset($item['sub']) && !empty($item['sub'])) {
       $output .= get_menu($item['sub'], $ulclass);
      }
      $output .= '</li>';
     }
    }
    $output .= '</ul>';
    return $output;
}

Existing Array:

$menu[] = array(
    'title' => 'Home',
    'href' => 'index.php'
);
$menu[] = array(
    'title' => 'Summer Activites',
    'href' => 'activities.php'
);
$menu[] = array(
    'title' => 'Winter Activities',
    'href' => 'wactivities.php'
);
$menu[] = array(
    'title' => 'Image Gallery',
    'href' => 'gallery.php'
);

I want to add submenus

ie: summer activities and winter activities would be child menu items under a parent Activities

Any help would be so appreciated Thanks in advance.

+1  A: 

Have you actually tried doing this or are you being lazy?

Practice makes perfect!

Lizard
+1  A: 
$menu[] = array(
   'title' => 'Activities',
   'sub' => array(
        array(
           'title' => 'Summer Activites',
           'href' => 'activities.php' ),
        array(
           'title' => 'Winter Activities',
           'href' => 'wactivities.php')
        )
    )
);

Looks like it should work.

Benjamin Cox
Was about to tell him to add a recursive function call. Somehow I missed that it was already there.
Tim Lytle
I thought that the sub was part of it, but there is something not quite right (there was one extra close parenthesis). I have zero background in coding so I am really winging it here. it's not faulting but the sub items are not showing. I think it's soooo close.and to respond to Lizard, I have been trying to figure this out but my area is print design, I am just doing this to help a friend out. With no coding knowledge, I'm trying my damdest to figure it out. I've figured out the rest of the coding for the site, just not this part. I am super appreciative of any help i can get.
Chase