I am practically new to Joomla and I need to get the SEF path of an article from an external php script. I feel like I'm close, but something is not working for me. The preliminary code I have as an example is:
require_once(JPATH_BASE . DS . 'includes' . DS . 'defines.php'); require_once(JPATH_BASE . DS . 'includes' . DS . 'framework.php'); $mainframe = JFactory::getApplication('site'); $mainframe->initialise(); $articleId = 80; $url = JRoute::_("index.php?option=com_content&view=article&id=" . $articleId);
With this, JRoute returns the path
/component/content/article?Id=80&Itemid=437. After doing some research, I read that I must include the "itemId" of the menu.
I'm not sure if it's the "437" that the JRoute returns to me, or if I should get it separately. Based on my reading, one way to get the menu item id is:
$link = 'index.php?option=com_content&view=article&id=' . $articleId; $menu = $mainframe->getMenu(); $menuItem = $menu->getItems('link', $link, true); $Itemid = $menuItem->id;
$Itemid returns empty. I would appreciate if someone could guide me with this. What I need is to build the SEF path of the article, regardless of its menu structure. My final need is to create a link to that article based on its articleID from an external php script.