[Wayfinder] How to get the first level id menu (parent)


I have a couple of problem with Wayfinder.

I have a menu with sub pages (3 level)
I should my first level only on the top of the page

Accueil - Séance Individuelle - Cours et Séances - L’Atelier - Evénements

Below, and at left side of the content, I want to display the level 2 and 3 only.

I added Wayfinder as the following:

[[!Wayfinder? &startId=`[[*id]]` &level=`2` &rowTpl=`rowTpl` &outerClass=`navbar-nav` &levelClass=`nav-item` &hideSubMenus=`0` &hereClass]]

It’s nice, but it does not works fine.

If I click on “Séance Individulle”, it catch the ID of that page and print all sub pages of “Séance Individuelle”.
If I click on one of the subpage of “Séance Individuelle”, the sub menu disepear, which sound logic, as


will get the ID of the select page,

My question is how can I make sure that


always get the ID of the first level item of the selected submenu, whatever if I click on the 2nd of 3rd level

For example, if I click on the submenu of “Scéance Individuelle”, I alway need to gte the ID of “Séance Individulle”

If I click on the sub-sub-menu of “L’atelier”, I alway get the id of “L’Atelier”.

I do not understand how getRessource can help?
findParent, look like to search for a parent if I inform a title, but I always want to have the first level parent, wathever the tile (title can change)

Many thanks

Maybe you can use the extra UltimateParent.

1 Like

Thanks a lot that’s work fine but I observer another problem.

I have to show the title of the sub page but only if there 3 level.
For example

menu3 (show on the top)
– menu3-1 (show on the right section)
---- menu3-1-1 (show on the right section)
---- menu3-1-2 (show on the right section)
– menu3-2 (show on the right section)
---- menu3-2-1 (show on the right section)
---- menu3-2-2 (show on the right section)
– menu4-1

(Note the first level is not print on the same place)
If I add

[[!Wayfinder? &startId=[[UltimateParent?id=[[*id]]&topLevel=1]] &level=2 &rowTpl=rowTpl &outerClass=navbar-nav &levelClass=nav-item &hideSubMenus=0 &hereClass]]

That print well the tree of the menu3, wathever the sub page I click.


if I click Menu3

The title shown on the top of the content must be


If I click menu3-1-2
The title on the top of the content must


I guess I could do as the following


But I see two problems

How can I check that [[UltimateParent?id=[[*id]]&topLevel=3]] is not the 2nd level only?

To clarify this
If I click Menu4-1, Menu4-1 has not a sub page, then it should only print the page title


My question: If I click wathever a page, is possible “to ask”:

Is the third level?
If yes, print its parent title as h1 and the the title page as h2
If not, print only the title page as h1

With Ultimateparent, is possible to make that control?

  • Is 3rd level?
  • What is direct parent title page?



print the ID. How can I print the title of the page?

I hope I was clear
Many thanks for your help

Maybe it’s best to write your own custom snippet. The following code might work, but honestly I’m not quite sure I understand exactly what you are trying to achieve.

$output = '';
$id = $modx->resource->get('id'); //id of current resource
$pids = $modx->getParentIds($id); //array of all the parent ids
$level = count($pids); //length of array = hierarchy level
if ($level == 3){
    //load parent resource
    $parent = $modx->getObject('modResource', $modx->resource->get('parent'));
    if ($parent) {
        //output the title of the parent resource
        $output .= '<h1>' . $parent->get('pagetitle') . '</h1>';
    //output title of current resource
    $output .= '<h2>' . $modx->resource->get('pagetitle') . '</h2>';
} else {
    $output .= '<h1>' . $modx->resource->get('pagetitle') . '</h1>';
return $output;
1 Like

Dear halftraindharry

Thanks a lot. It help me a lot!!

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.