0

Does anybody know a way to find out which menu item an article is attached to in Joomla 3.x ? When you open a menu item you can see which article is attached to that menu. But the opposite is not shown. How can I see which menu(s) an article is attached to?

1

To get menu items assigned to specific article, where $articleId is the article ID:

$assignedItems = array();

// Get all Articles component menu items.
$menuItems = JFactory::getApplication()->getMenu('site')->getItems('component', 'com_content');

foreach ($menuItems as $menuItem)
{
    // Check that menu item is for article view and that IDs match.
    if ($menuItem->query['view'] === 'article' && $menuItem->query['id'] == $articleId)
    {
        $assignedItems[] = $menuItem;
    }
}

There's a simpler way but it doesn't account for different layouts, if any, and additional menu item URL parameters that might be added by plugins:

$assignedItems = JFactory::getApplication()->getMenu('site')->getItems('link', 'index.php?option=com_content&view=article&id=' . $articleId);

The rest depends on where and how exactly you want to display the items.

  • Thanks for the reply. But I was wondering if there is a way to do this in administrator page. I don't even know where and how to use this code.. – Sinan Dec 4 '18 at 18:57
  • Which page? Article form? – Sharky Dec 6 '18 at 6:46

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.