Monday, December 28, 2015

Joomla - displaying parent menu items


In Joomla 3 ,  get the level 1 (parent) menu items like title, alias and route with the given menu type.

            $app  = JFactory::getApplication();
            $menu = $app->getMenu();
            $menu_items = $menu->getItems('menutype', 'side-navigation');
            if(!empty($menu_items))
            {   
                foreach($menu_items as $item)
                {
                   $menu_title = $item->title;
                   $menu_alias = $item->alias;
                   $menu_route = $item->route;
                   $menu_level = $item->level;
                   if($menu_level==1)
                   {   
                 ?> 
                   <li><a href="<?php echo JURI::base(); ?><?php echo $menu_alias; ?>"> <?php echo $menu_title;?> </a></li>
                <?php
                   }
                }
            }

No comments:

Post a Comment