开发者

How do I take this existing array and add submenus?

Exist开发者_Go百科ing 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.


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

Practice makes perfect!


$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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜