Peter Knight Posted August 26, 2014 Share Posted August 26, 2014 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 More sharing options...
Martijn Geerts Posted August 26, 2014 Share Posted August 26, 2014 Maybe this: $page->rootParent or $page->closest($selector) Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 26, 2014 Share Posted August 26, 2014 … UltimateParent would only list sub-pages of the current Page. This would be: $subpages = $page->children; Link to comment Share on other sites More sharing options...
Peter Knight Posted August 26, 2014 Author Share Posted August 26, 2014 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 More sharing options...
mr-fan Posted August 26, 2014 Share Posted August 26, 2014 Maybe its worth to check this one....for me this is menubuilding like a boss http://modules.processwire.com/modules/markup-simple-navigation/ nearly erverthing could setup with this one sometimes with little addtions but this addon is a real timesaver. Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 26, 2014 Share Posted August 26, 2014 I don't know the module, but 'selector' => '', 'selector_field' => 'nav_selector' should be your friend in setting the parent, if I understand it right. Link to comment Share on other sites More sharing options...
mr-fan Posted August 26, 2014 Share Posted August 26, 2014 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 More sharing options...
Soma Posted August 26, 2014 Share Posted August 26, 2014 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); 3 Link to comment Share on other sites More sharing options...
Peter Knight Posted August 26, 2014 Author Share Posted August 26, 2014 Thanks Soma. Happy days @mr-fan Re. RTFM you're right. I need to familiarise myself with selectors more and how to use them. hazards of choosing a new CMS on a tight deadline. Link to comment Share on other sites More sharing options...
mr-fan Posted August 26, 2014 Share Posted August 26, 2014 I switched CMS too......I've the comfort of a small project without a deadline. But learning PW is faster as any other cms ! As fast as this forum and the real talented users share and awnsers 2 Link to comment Share on other sites More sharing options...
Peter Knight Posted May 25, 2015 Author Share Posted May 25, 2015 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 ProductsRockets Spacecraft Submarines StaffEngineering TeamAlan John Miriam Ballistics TeamPhil Tracey Liam Strategy & Planning TeamPeter Adrian Mary LocationsMoonStation Lunar Station Solar EarthUSA 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 StaffEngineering Team Ballistics TeamPhil 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 More sharing options...
Soma Posted May 27, 2015 Share Posted May 27, 2015 I'm not sure I understand it correctly. But what if you set 'max_levels' => 3, 'collapsed' => true, collapsed means it only shows the current branches. Link to comment Share on other sites More sharing options...
Peter Knight Posted May 27, 2015 Author Share Posted May 27, 2015 @Soma That's what I needed. I hadn't tried those two in conjunction with each other. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now