pathway

Add or remove items in the Joomla breadcrumb system

As I’m sure you’re aware, the Joomla breadcrumb / pathway is built from the nested menu structure of your current page.  If you’ve developed a page that is not linked up in the menu, or want to edit the pathway for any reason, try this snippet:

//this returns the pathway object for manipulating
$pathway = JFactory::getApplication()->getPathway();  
//append item on the end of the pathway - first argument for the name, the second (optional) for a link
$pathway->addItem('Designers','index.php?Itemid=115'); 
//append just a name to the pathway
$pathway->addItem('Hello hello');

When adding an item to the pathway with a link, note that the link will automatically be JRouted to give you lovely SEF URLs – perfect!

Modifying items in the breadcrumb trail

So you want modify page names or links listed in the pathway but not sure how? This section of code shows you two ways on how to achieve this (description below):

//get the JApplication object for this session
$app = JFactory::getApplication();
//get the pathway object of the current page
$pathway = $app->getPathway();

//this function returns the array of pathway objects, allowing you to modify it
$pathwayarray = $pathway->getPathway();
//this will update the link for the first element in the pathway (the 'home' element is not included - it must always be there)
$pathwayarray[0]->link = 'index.php?Itemid=999';

//Then use setPathway to update the breadcrumbs with your modified path!
$pathway->setPathway($pathwayarray);

//you can also update pathway names using the built-in function setItemName:
//this will update the first element in the pathway with the title 'New title'
$pathway->setItemName(0,'New title');

Hopefully this is fairly self-explanatory.

Resetting the Joomla Pathway

Sometimes rather than editing the pathway, you might want to remove it entirely and start again.  This is easy, just set the pathway as we did before, but to an empty array.  Then continue to add items to the pathway to build your own!

//get the JApplication object for this session
$app = JFactory::getApplication();
//get the pathway object of the current page
$pathway = $app->getPathway();
//set the pathway to an empty array, to reset it
$pathway->setPathway($array);
//add items to the pathway as desired - remember the links will automatically be JRouted, giving you nice SEF URLs
$pathway->addItem('Category listing','index.php?Itemid=493');
$pathway->addItem('Cars','index.php?Itemid=693');
$pathway->addItem('Mazda');

The code above will give you a pathway of Category listing > Cars > Mazda, with links where a second parameter is given of course.

For more information on the pathway object, see the Joomla documentation.

 Scroll to top