How to get menu Itemid in your own components

/ Published in: PHP
Save to your folder(s)

Joomla SEF to work properly it is based on Joomla menus. In your own components for SEF to work and menus to appear your need to pass the Itemid to links. To do this you need to get the Itemid based on on the URL link. Here is how you get the Itemid by link.

This code gets the Itemid of a menu link when you know the component and the view

Copy this code and paste it in your HTML
  1. $url = 'index.php?option=[[option]]&view=[[view]]';
  2. $menu = &JSite::getMenu();
  3. $menuItem = $menu->getItems( 'link', $url, true );
  4. $Itemid = $menuItem->id;

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.