N
N
Nikolai Novosad2017-11-20 22:44:58
Drupal
Nikolai Novosad, 2017-11-20 22:44:58

How to get the ID of the parent menu item?

Hello. I use Drupal 7.
Please tell me how can I get the ID of the parent menu item?
My menu structure is:
--About
----About Child 1
----About Child 2
----About Child 3
----About Child 4
--Team
--Products
----Product Child 1
----Product Child 2
----Product Child 3
--Contacts
And when I go to the 'About Child 2' page, I need to get the parent's ID. In this case it is 'About'. Child page url is not ' site.com/about/about-child-2 ' but ' site.com/about-child-2 '
I need to get the ID in the 'theme_breadcrumb()' function. Let's say I can get the id of the current page through the 'drupal_get_normal_path()' function, but I can't get the parent menu item any further.

function theme_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];
  $current_id = drupal_get_normal_path($_GET['q']);
  
// дальше не получается. пробовал, но получал только ID главной страницы
}

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
andead, 2017-11-21
@andead

$menu_trail = menu_get_active_trail();
$parent_item = $menu_trail[count($menu_trail) - 2];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question