How can I extend the functionality to include the parent item in the menu?

If my Primary Links menu is


etc. then setting the menu to Primary Links, the item to and starting level to 2 then when I go to Foo1 the menu is


when I'd like


This seems to be the way the Druaplcon site works at - do I have to manually add in an entry for Foo1 to the menu so it's


or is there a better way?


new1.58 KB

I couldn't see any way to do that either without setting the block title, which I see as error prone.

Attached is a patch with my solution

Cool module

Sorry for the newbie question: To which file is the patch supposed to be applied?


I tried to implement your patch, but could not get it to work. Instead,

when at




all I saw was


Is there a setting that needs to be set so that only


can be seen? I don't want to see all the other Parent links, jut the Parent link that is active, and its children in a sidebar.

Thanks for your help.

Status:Active» Needs review

I got this patch to work fine (rolled against the current release 6.x-2.2), although needed to check the Expand children: > Expand all the sub-menus of this tree option to get it to work as planned; I also set starting level to '1st with parent' (which is the option the patch adds) and Maximum depth to 2.

This is a really useful addition to menu block and I have suggested that this code should be reviewed. Hopefully this functionality will make it into a future release of the module.

Thanks @hefox

Thanks @hefox

i got this to work perfectly for one of my menus. exactly what i was looking for.

it would be great to be able to choose 2nd level with parent!
anyone know how to do that?

hefox, et. al,

The patch does work, sorry for the confusion. Though, I did misinterpret what I though the patch was going to do.

I am looking for what alburton I think is suggesting by "2nd level with parent."

That is, show a second level link and only the parent it is connected to, not all the other menu items at the parent's level.

For example

If I click on Parent1 (or any of its children), I see:


and not


Maybe you could use the cool new features in -dev : #345419: Add option for menu title as link.

Since John committed the solution above, I don't think patches in that issue could be committed.


edit: the patch worked for me, this is exactly what I needed. It messed with my CSS a little but that can be fixed.

The other thing I just learned about is to use the command line to apply the patch, in my case Terminal in OS X. I took the patch and put it in the same directory as the files to be patched and then used the command:

patch -b < menu_block_show_parent.patch

This saves lots of time. If your site is online and you don't have ssh access you could download the folder with the module to be patched via FTP, make a temp folder on your hard drive and then do the patching and reupload.

Version:6.x-2.2» 6.x-2.3
Status:Needs review» Reviewed & tested by the community
new846 bytes
new523 bytes

Just hacked around and re-rolled the patch for 6.x-2.3 (#1 won't work against he latest release). Uses the same code that @hefox worked out and seems to work fine...

I'm not a great patch roller... so it's 2 separate files. (off topic: can the text from 2 sep patches just be merged to create a single file?)

(@snorkeys, yes I've done it a few times (combine patches) XP.

For me, this patch breaks menu items more than 2 levels deep. If I include the parent, the block doesn't show up at all.

Any fixes?

Status:Reviewed & tested by the community» Needs work

The patch didn't work for me, and a good solution should be to make an 'add parent to menu links' checkbox available on all levels, not just first.

Has there been any progress with this? This seems to be the right direction, but the patch in #9 is not working (for me at least).

This would be a great feature.

new5.36 KB

Here's a patch against 2.3. Instead of the arbitrary depth limit of 1 in the previous patch, this should support unlimited depth below the parent menu item using the existing level selection dropdown. It just provides a checkbox on the block settings called "Include Parent"...

Status:Needs work» Needs review

setting it to needs review

new4.74 KB

I've modified stockliasteroids patch a bit to also work for sub menu blocks that don't have a parent menu item selected but only a menu.

Believe it or not, but all it took was highrockmedia's reply to start patching for the first time. Other tutorial pages seemed a little overwhelming to me.

Thank you, highrockmedia, for this valuable entry.

Just what I was looking for - thanks. This option should be available by default.

I ported the patch provided in comment #17 (thank you!) to Drupal 7 including some minor improvement, see #1045352: Including parent item in the menu

Version:6.x-2.3» 6.x-2.4
Category:support» feature
Status:Needs review» Reviewed & tested by the community

I've just rolled the patch at #17 against 6.x-2.4 and works (with a few offsets). The patch certainly works, and it seems that there are at least 2 others that have tested it => RTBC.

new4.74 KB

i can confirm that the patch is working with 6.x-2.4.

attached you can find a re-roll of the patch in #17 which just removes the offset warnings.

Version:6.x-2.4» 7.x-2.x-dev
Status:Reviewed & tested by the community» Needs review
new4.56 KB

I've manually applied the patch from #22 to 7.x version files, and everything seems to be functioning as expected.

Nice to see that it works in 7.x. But was the 6.x-2.4 patch committed? If not can it be left at RTBC and a separate issue for D7 started?

new6.62 KB

Some time ago, I adapted the patch from comment #17 for D7 with some minor additions (work for menus of arbitrary levels and do not add the parent item as the only item in the menu), see #1045352: Including parent item in the menu. I was asked to to post the patch here, so this is what I do.

Just tried this patch and it fails test -- menu_block version info listed below as is the fail

Any ideas ??


patching file b/sites/all/modules/menu_block/
Hunk #1 FAILED at 246.
Hunk #2 FAILED at 356.
2 out of 2 hunks FAILED -- saving rejects to file b/sites/all/modules/menu_block/
patching file b/sites/all/modules/menu_block/menu_block.module
Hunk #1 FAILED at 180.
Hunk #2 FAILED at 196.
Hunk #3 FAILED at 317.
Hunk #4 FAILED at 505.
Hunk #5 FAILED at 516.
Hunk #6 FAILED at 538.
6 out of 6 hunks FAILED -- saving rejects to file b/sites/all/modules/menu_block/menu_block.module.rej

menu_block version:

Project : menu_block
Type : module
Title : Menu Block
Description : Provides configurable blocks of menu items.
Version : 6.x-2.4
Package : Other
Core : 6.x
PHP : 4.3.5
Status : enabled
Path : sites/all/modules/menu_block
Schema version : 6201
Requires : block, menu
Required by : none

Works like a charm!

I reattempted patch and it worked fine this time.



Does anyone have a patched version of the D7 menu block module that I can use?


as I am not able to apply the patch easily myself.


new43.45 KB

mjpg, attached you find the 7.x-2.2 version, patched with my patch from comment #25

Many thanks - still not quite working but I suspect that it may be the dual language versions of the pages with two menu entries causing an issue.

thank you for this patch! working great.

for #30 to work, I had to set the maximum depth to 2 or more (i had it on 1) otherwise you only see the parent item.

Indeed Yuri, the maximum depth should be set to "2", which leads to the menu being built up in a list within a list.

Is there a way this behaviour doesn't occur? In other words: is it possible to add both the parent item and the subitems in one list?

Here's what I mean:

Currently this is the case:

  <li>Parent item

Here's what I'd prefer:

  <li>Parent item</li>

If this isn't possible or if it's bad practice (confusing for SEO), then it's still possible to solve that through CSS layout-wise.

Due to issues from the Drupal 7.12 upgrade it seems that we're forced to upgrade to Menu Block 2.3.
#1425342 Drupal core upgrade from 7.10 to 7.12 causes menu block to fail

I was happily using Ronino's patch at #25

I'm not sure if the Menu Block 2.2 patch will work on Menu Block 2.3?

It would be so great to get the "Include parent" functionality included in Menu Block that this patch provides.

i re-applied Ronion's patch at #25 to Menu Block 2.3 post drupal 7.12 upgrade and all appear to work as expected for me

Menus disappear when you set the "Fixed parent item" to something more than one level deep
(If I start one level deep things are fine)
I'm on drupal 7.12 and menu_block 2.3 and have applied the #25 patch without errors

Any ideas??

e.g. of what I'm after

-- PARENT ITEM THREE ( I want to start here)

I'd like to create a menu block that looks like

I'm on drupal 7.14 w/ menu_block 2.3 and the patch from #25 seems to work perfectly for me.

Looks like this issue has been going on for a while - any way we can get this feature into a release? Is there anything blocking its inclusion?

Status:Needs review» Reviewed & tested by the community

I'm on 7.15 and Menu Block 2.3 and also confirm this patch is working great for me. It would be nice indeed to have this feature in the future release.

Patch #25 worked for me (using 2.3). This should be included in the module!

+1 please approve and release

#25 worked for me using menu_block 7.x-2.3.

Thank you. Patch in #25 worked perfectly for me with 7.x-2.3 once I remembered how to apply a patch using the cmd line rather than cut and paste!

Will this be included into the module?

How is everyone applying this patch from #25?

I have tried many different variations:
patch < menu_block_include_parent_d7_0.patch
patch -p1 < menu_block_include_parent_d7_0.patch
patch -p0 < menu_block_include_parent_d7_0.patch
git apply -v menu_block_include_parent_d7_0.patch

Nothing seems to work

gmclelland, from what directory did you try to apply the patch?

new7.33 KB

@Ronino - Thanks for the reply. I tried running those commands from the root of the module.

Here is a untested manual reroll of #25 that should apply against MB 2.3.

Hope it helps someone.

new7.78 KB

Here's a new patch rerolled against 7.x-2.x-dev and tested on Drupal 7.23.

Anyone who (like me) is eager to have this feature committed should install 7.x-2.x-dev, test this patch and report back. It's a good feature.

Re comment #37 - also tested on a menu block starting on third leve; works fine.

Thanks everyone.

Status:Reviewed & tested by the community» Needs review

After patching this I am getting this Notice:

Notice: Undefined index: include_parent in menu_tree_block_data() (line 284 of /profiles/panopoly/modules/contrib/menu_block/menu_block.module).


Sounds like it may not have applied properly to Which patch and which version of menu_block?

the patch from #48 and the current dev. I applied the patch manually.

@tchopshop -

If you've applied the patch manually, it's difficult for me to troubleshoot. As you can see from the error, $config['include_parent'] is undefined. If the patch was applied properly, this index should be defined in the function menu_block_get_config(). The only other thing I might suggest is that, if you already have a menu block defined, then you may need to resave your block configuration. Let us know if you make any progress.

Issue summary:View changes
Status:Needs review» Needs work

We're running into the same issue as #37. If our parent is at the top of the menu then it works great. However it our parent (as designated in the menu block config) has a parent menu item of it's own, then it returns nothing.

The issue seems to be stemming from the logic inside menu_tree_prune_tree...

+          if (!empty($include_parent)) {
+            $tree = array($key => $tree[$key]);
+          } else {
+            $tree = $tree[$key]['below'] ? $tree[$key]['below'] : array();
+          }

If I were to comment out the if condition and just use...

$tree = $tree[$key]['below'] ? $tree[$key]['below'] : array();

... the menu block renders a menu, though without the parent. It's when we reset the $tree to the parent item instead of the children ('below') that the logic check of

if ($tree[$key]['link']['mlid'] == $plid) {

fails and we eventually hit the !$found_active_trail condition which wipes out any results.

I'm still debugging to figure out why... but i've narrowed it down to that part of the patch that seems to be the cause of the issue.

Status:Needs work» Needs review
new7.39 KB

Attached is a new patch which is just a small modification to the patch in #48. I've tested this against 7.x-2.x and 7.x-2.3 locally. I did have to manually apply the patch to 7.x-2.3.

Difference between the two patches is small...

#48: if (!empty($include_parent)) {
#55: if (!empty($include_parent) && $plid != $parent_item['plid']) {

This solved the issue we were experiencing noted in comment #37 above.

Brilliant. The patch is good and solves the problem described in #54.

I SO want to mark this as reviewed and tested but I suppose we should wait for one or two others to chime in.

Thanks, @caschbre!

Issue summary:View changes

Issue summary:View changes

How can I make the same with Better Jump Menus module...



Go to the Better Jump Menus issue queue and post your question there.

Hi there,
I needed a special background color for a menu block when it´s parent item is active (
With the patch from #55 I could do that.
In CSS i had to set diplay:none for the parent li-item and for it´s sub-items I set diplay:block.
But with the presence of the selector "" of the parent item, I can now style the block.

Status:Needs review» Reviewed & tested by the community

Thanks @4kant. I think this qualifies as reviewed and tested. I checked and no re-roll is required.

The patch in #55 is working for me. It does not apply against 2.3, but it does apply against Dev. (I tested against revision 8dd19f03.)

The patch #55 is working for me too (REMEMBER: it applies only on DEV).

This patch works for me. Testing in a fresh install, using the following steps:

  1. Install as normal. Ensure menu_block is enabled.
  2. Enable devel and devel_generate. (This makes it easier to create a menu tree without manually creating a bunch of menu items: "drush en devel devel_generate"
  3. Generate some content: "drush generate-content 50" to generate 50 pieces of content.
  4. Generate menu items: "drush generate-menus 1 20 9" (Parameters are weird, but that's 1 menu, 20 links, and a max-depth of 9)
  5. Add and configure menu block for the generated menu at admin/structure/block
  6. Observe the block in it's natural habitat.

A couple of minor code comments:

  1. +++ b/menu_block.module
    @@ -199,17 +199,18 @@ function menu_block_get_all_menus() {
    +    'delta'          => $delta,
    +    'menu_name'      => 'main-menu',
    +    'parent_mlid'    => 0,
    +    'parent'         => '',
    +    'title_link'     => 0,
    +    'admin_title'    => '',
    +    'include_parent' => 0,
    +    'level'          => 1,
    +    'follow'         => 0,
    +    'depth'          => 0,
    +    'expanded'       => 0,
    +    'sort'           => 0,

    This also needs to be updated in hook_menu_block_blocks() in menu_block.api.php

  2. +++ b/menu_block.module
    @@ -592,8 +596,12 @@ function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE) {
    +          } else {

    Sorry this is so nitpicky... We prefer closing braces on their own lines.

  3. +++ b/menu_block.module
    @@ -616,8 +624,14 @@ function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE) {
    +        } else {

    Here too. (Still nitpicky)

Nothing wrong with nitpicky. Here's another go.