Jump to content

Ultimateparent in navigation


Peter Knight
 Share

Recommended Posts

In MODX there's a snippet call Ultimate Parent.

I use it for building sub-menus on the left navigation of my pages. IE Whereas my top nav would list all level 1 pages, UltimateParent would only list sub-pages of the current Page.

@example [[ultimateParent? &id=`45` &top=`6`]]
* Will find the ultimate parent of document 45 if it is a child of document 6;
* otherwise it will return 45.
*
* @example [[ultimateParent? &topLevel=`2`]]
* Will find the ultimate parent of the current document at a depth of 2 levels
* in the document hierarchy, with the root level being level 1.
*
* This snippet travels up the document tree from a specified document and
* returns the "ultimate" parent. Version 2.0 was rewritten to use the new
* getParentIds function features available only in MODx 0.9.5 or later.
*

Is there a PW module for this or would it be simply a case of using some PHP with the API?

Link to comment
Share on other sites

Can it be done with Soma's SimpleMarkupNavigation? It seems to have more control over setting the options but I can only seem to work it by starting at the root and not the parent

 <?php $treeMenu = $modules->get("MarkupSimpleNavigation"); // load the module
		  
		  $options = array(
				'parent_class' => 'parent',
				'current_class' => 'current',
				'has_children_class' => 'has_children',
				'levels' => true,
				'levels_prefix' => 'level-',
				'max_levels' => 1,
				'firstlast' => false,
				'collapsed' => true,
				'show_root' => true,
				'selector' => '',
				'selector_field' => 'nav_selector',
				'outer_tpl' => '<ul>||</ul>',
				'inner_tpl' => '<ul>||</ul>',
				'list_tpl' => '<li%s>||</li>',
				'list_field_class' => '',
				'item_tpl' => '<a href="{url}">{title}</a>',
				'item_current_tpl' => '<a href="{url}">{title}</a>',
				'xtemplates' => '',
				'xitem_tpl' => '<a href="{url}">{title}</a>',
				'xitem_current_tpl' => '<span>{title}</span>',
				'date_format' => 'Y/m/d',
				'code_formatting' => false,
				'debug' => false
			);
				echo $treeMenu->render($options); // render default menu ?> 
Link to comment
Share on other sites

Hi sparrow,

;) (RDFM) you will found this direct under the addonsdownload:

  • Overwrite current page or root page
  • Build a menu using a PageArray instead of a single root page

so may you've got two menus one for the firstlevel and one for the second/subsites.

In the basic theme that is shipped with the installation there is an example with the API and some if/foreach stuff that works without the addon.

regards mr-fan

more deeper in the added/updates section there is a good example to test/try

added support for nav_selector property/field and selector_leveln (new in 1.2.1)

You can now add a special property "nav_selector' to page(s) to define custom selector for rendering their children. This can be done on runtime or via a custom field added to pages to remotely control the selector. You can configure the name of the field by using the newly added option "selector_field". MarkupSimpleNavigation will look out for it and use it, otherwise it will use the "selector" option.

You can now define selector on a per level basis. Simply use the _leveln suffix on the "selector" option, where n is the level number from the root parent. This is best illustrated by the following example:

$pages->get(1001)->my_selector = "template=projects";

$options = array(
  "selector_level1" => "template=ressort",
  "selector_level2" => "start=0, limit=10",
  "selector_level3" => "template=news|events, sort=-created",
  "selector_field" => "my_selector"
);

echo $nav->render($options);

Note that "my_selector" has priority and will overwrite any other selctor or selector_leveln

Link to comment
Share on other sites

Something like this can be done

Top root menu

// default root is "/"
echo $treeMenu->render(array("max_levels" => 1));

Submenu 

$root = $page->rootParent; // top root parent of current page
echo $treeMenu->render(array("max_levels" => 1), null, $root);
  • Like 3
Link to comment
Share on other sites

  • 8 months later...

I'm late getting back to this  ???

Just to recap, I have a side navigation bar. For the purposes of explanation, if it was completely expanded (which it never is), it would look like this

  • Products
    • Rockets
    • Spacecraft
    • Submarines
  • Staff
    • Engineering Team
      • Alan
      • John
      • Miriam
    • Ballistics Team
      • Phil
      • Tracey
      • Liam
    • Strategy & Planning Team
      • Peter
      • Adrian
      • Mary
  • Locations
    • Moon
      • Station Lunar
      • Station Solar
    • Earth
      • USA
      • Germany
      • Ireland
      • France
      • England

The menu correctly displays as 

  • Products
  • Staff
  • Location

with ​'max_levels' => 1

However if I was to send someone a direct link to a level 3 page ( Staff > Ballistics Team > Tracey)

then I want the side menu to display that page, all level 3 siblings (Phil, Tracey and Liam), it's level 2 root pages and it's level 1 parent(s)

  • Products
  • Staff
    • Engineering Team
    • Ballistics Team
      • Phil
      • Tracey
      • Liam
    • Strategy & Planning Team
  • Locations

As mentioned by mar-fan there has since been options added for selector_leveln properties but I'm not sure if thats what I need?

added support for nav_selector property/field and selector_leveln (new in 1.2.1)

Here's my working menu which has  ​'max_levels' => 1

<?php $treeMenu = $modules->get("MarkupSimpleNavigation"); // load the module
		  
		 	 $options = array(
				'parent_class' => 'parent',
				'current_class' => 'current',
				'has_children_class' => 'has_children',
				'levels' => true,
				'levels_prefix' => 'level-',
				'max_levels' => 1,
				'firstlast' => true,
				'collapsed' => false,
				'show_root' => true,
				'selector' => '',
				'selector_field' => 'nav_selector',
				'outer_tpl' => '<ul class="sidelist">||</ul>',
				'inner_tpl' => '<ul>||</ul>',
				'list_tpl' => '<li%s >||</li>',
				'list_field_class' => '',
				'item_tpl' => '<a href="{url}">{title}</a>',
				'item_current_tpl' => '<a href="{url}" >{title}</a>',
				'xtemplates' => '',
				'xitem_tpl' => '<a href="{url}">{title}</a>',
				'xitem_current_tpl' => '<span>{title}</span>',
				'date_format' => 'Y/m/d',
				'code_formatting' => false,
				'debug' => false
			);

		$root = $page->rootParent; // Start from the top root parent of current page
		echo $treeMenu->render($options, null, $root);
	
	
?>	

Thanks guys.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...