How to get specific menu items from joomla?

后端 未结 9 2045
孤独总比滥情好
孤独总比滥情好 2020-12-08 21:51

This question is bit specific for Joomla.

I have a main menu consisting of:

Home|About US|Privacy Policy|Portfolio|Contacts US.

Each menu it

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 21:58

    The easiest way to accomplish this in 2.5+ is:

    $app = JFactory::getApplication();
    $menu = $app->getMenu();
    $menu_items = $menu->getItems('menutype', 'mainmenu');
    

    Just replace 'mainmenu' with the menutype that you want to pull. This would equate to the system name for your menu, the same as you would select in the menu module.

    Edit in response to @betweenbrain's question below: Get the menu object the same way as above, then:

    // To get menu items filtered by access level of current user.
    $filtered_menu_items = $menu->getItems(null, null);
    
    // To get all menu items, unfiltered.
    $all_menu_items = $menu->getMenu();
    

提交回复
热议问题