0

I'm wondering if there's a way to see which Menu Item is associated with an Article.

I know this is easy from the Menu Item -> Article view, since Articles are assigned in Menu Items.

If I'm in an Article, is there a field or way for me to see its associated Menu Item?

1
  • Welcome to JSE, please take our tour and perhaps introduce yourself and tell us about your Joomla journey in your profile. Commented Sep 10, 2020 at 22:48

1 Answer 1

1

You'd need to write some code to do it, but it wouldn't be hard.

To get a list of all the menuitems on your Joomla site you can do:

use Joomla\CMS\Factory;
$app = Factory::getApplication();
$sitemenu = $app->getMenu();
$menuitems = $sitemenu->getItems(array(), array());

Then you can cycle through the $menuitems examining the query property which is an array with values something like array("option" => "com_content", "view" => "article", "id" => "123").

So you could write an administrator module to do what you want.

Inside the module look for the case where an administrator is editing an article, indicated by your URL parameters being something like ?option=com_content&view=article&layout=edit&id=123. Then run the code above, look for where the query property has the appropriate values, and matches the id of the URL parameter, and then output the title for each matching menuitem.

You can find a guide to the menuitems API here, and on that page there is sample module code to get you started.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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