Torben
Torben

Reputation: 5494

Drupal 7 - How to get menu trail?

i have a URL like: domain.com/content/travel in my drupal installation.

In D6 i used the following code to extract "travel" from the above mentioned trail:

$menuParent = menu_get_active_trail();
$path = $menuParent[1]['page_arguments'][0]->path;
$pathArray = explode('/', $path);
$menuParent = $pathArray[1];
$menuChild = trim($pathArray[3]);

This is not working in D7 anymore as menu_get_active_trail only delivers the "node/4" URL. How can i get the URL as mentioned above in D7?

Thank you!

Upvotes: 0

Views: 797

Answers (1)

TheodorosPloumis
TheodorosPloumis

Reputation: 2456

You can use the drupal_get_path_alias() function to get the path alias of active trail.

$menuActive = menu_get_active_trail();

// Get the path alias from active trail
$menuParent = drupal_get_path_alias($menuActive);

$path = $menuParent[1]['page_arguments'][0]->path;
$pathArray = explode('/', $path);
$menuParent = $pathArray[1];
$menuChild = trim($pathArray[3]);

Upvotes: 1

Related Questions