Take the tour ×

This question is bit specific to joomla.

I know if with the code $menu = &JSite::getMenu() I can get the reference object of the complete menu. But how can i get a specif menu based on the name?

My Scenario : I have footer-menu with items : home | about us | rules | privacy policy.

I need to display links to two menu items Rules and privacy policy in a component. I cannot hard code the links, as the itemid would be different in development and production environment.

Do we have some workaround like $menu = &JSite::getMenu()->get('footer-menu')->getMenuItem('rules'); which can give me refrence object to a particular menu item, from which I can create my links for that particular article.

Thanks, Tanmay

share|improve this question
Seems its friday fever!!! :( no one seems to be online... Please help me.. atleast on Monday :) –  jtanmay Aug 13 '10 at 19:29
any hints please!!!! –  jtanmay Aug 16 '10 at 15:16
add comment

2 Answers

Method #1:

$menu = & JSite::getMenu();
$item = $menu->getItems('link', 'index.php?option=com_content&view=article&id=1', true);

Method #2:

$menu = & JSite::getMenu();
$item = $menu->getItems('alias', 'rules', true);
share|improve this answer
add comment

As far as I know, there isn't a built-in way to do this. But I feel your pain.

Here's an adaptation of a function I built before. It's not recursive, so you'll only get one level deep in a menu hierarchy, but that was enough for me.

function getMenuItems( $parentAlias ) {
    $db =& JFactory::getDBO();
    $sql = 'SELECT * FROM #__menu WHERE parent in ' .
           '(SELECT id FROM #__menu WHERE alias='.$db->Quote($parentAlias).') '.
           'AND published=1 ORDER BY ordering';
    $results = $db->loadObjectList();

Let me know if this works for you.

share|improve this answer
Garrett Bluma, Well at the end I did something bit similar to your implementation, created a function in the model, to get me object for the menu items I want. Thanks for your reply. At least it confirmed that i am not missing a great function of joomla :) –  jtanmay Aug 19 '10 at 19:02
add comment

Your Answer


