Show parent in auto-nav or page list
Permalink
Hi! This is my second "problem" today.
Is there a way to show the parent page in page lists?
When I have a page called "Products" with a page-list and there's a lot of stuff in the list, I would want a link called "Products" to be in the top.
Is there a solution to do this with either page-list or auto-nav?
Is there a way to show the parent page in page lists?
When I have a page called "Products" with a page-list and there's a lot of stuff in the list, I would want a link called "Products" to be in the top.
Is there a solution to do this with either page-list or auto-nav?
I have the same problem. I have a sidebar auto nav which shows a menu of subpages, but I also want the parent page to be the top nav item. Is there an easy way to do this with auto nav. It seems that it should be a feature to 'include parent in list'.
I have been searching and found a post that said you can grab the Parent ID and get the attribute information - they gave the following code:
However I think it is missing something probably obvious to those more familiar with Concrete. How, from this code do I display the name of the parent page?
e.g., If I wanted to display the current page's name I would add -
$parentPage = Page::getByID($c->cParentID); $parentPage->getAttribute('myAttributeHandle');
However I think it is missing something probably obvious to those more familiar with Concrete. How, from this code do I display the name of the parent page?
e.g., If I wanted to display the current page's name I would add -
Is there no way to do this with concrete? An example would be awesome.
I really appreciate the help. That change in the code did it!
Aer there docs somewhere that explain some of the functions like getCollectionParentID and getCollectionName?
I am guessing there are but I didn't see them.
Aer there docs somewhere that explain some of the functions like getCollectionParentID and getCollectionName?
I am guessing there are but I didn't see them.
Is there a similar way to get the URL of a page in that way? I'm doing something similar to this in a custom autonav view, and I want the displayed name of the parent page to link to that page. So something like:
Is there a method of the Page class or something else that does that? I can't seem to find it in the API.
$url = $page->getCollectionURL();
Is there a method of the Page class or something else that does that? I can't seem to find it in the API.
<?= View::URL($page->getCollectionPath()); ?>
Just what I needed. Thanks!
I am looking to add a link to the parent page and do not know how to use the code you shared to make it work. I used the code above shared by andrew to get the parent page to display. Could you share what it would look like using what you shared to get that parent page to act as a link to itself?
Thanks so much.
Thanks so much.
This worked great for me. Thanks!
One point of help would be how I can make it no display the home page.
More specifically, if I have the following, for example:
Home
-About
--Company
--Facility
-Services
-Contact Us
When someone is on a sub page, ie. Company or Facility - I want the top level title to show above in the menu (About).
But when someone is on the About page - because C5 forces a hierarchy with Home above the rest, the result is that "Home" shows up when on the About page, or Services, etc.
Help?
Thanks,
One point of help would be how I can make it no display the home page.
More specifically, if I have the following, for example:
Home
-About
--Company
--Facility
-Services
-Contact Us
When someone is on a sub page, ie. Company or Facility - I want the top level title to show above in the menu (About).
But when someone is on the About page - because C5 forces a hierarchy with Home above the rest, the result is that "Home" shows up when on the About page, or Services, etc.
Help?
Thanks,
There are not that many options in the auto nav block and more customization for making menus would be helpful.
Being able to display a sidebar menu that auto puts the parent page up top and then all sub-pages of that parent page below, including the page one is on - that is a very basic and common way to add a sidebar navigation. Can this be added to a list for improvement?
Thanks,
Being able to display a sidebar menu that auto puts the parent page up top and then all sub-pages of that parent page below, including the page one is on - that is a very basic and common way to add a sidebar navigation. Can this be added to a list for improvement?
Thanks,
Found what I was looking for and wanted to share it.
http://icode4you.net/display-page-title-top-parent-menu-item-sub-pa...
http://icode4you.net/display-page-title-top-parent-menu-item-sub-pa...
In the context of a page_list template, you can use this to get the parent page object.
$parent = Page::getByID($this->controller->cParentID);
I'm sorry to necro this old thread but I thought this was better than creating new since googling the issue brought this thread up first.
Basically I've got a site tree like so:
Home
->First Level Page
-->Second Level (Parent)
--->Second Level Child Page 1
--->Second Level Child Page 2
--->Second Level Child Page 3
I want to create an autonav custom template that lets me display the second level page (parent) at the top, linked to said parent, and then the children underneath as normal.
In the autonav settings I'm choosing "Look at pages below a specific page" which in my example would be "Second Level (Parent)".
I'm getting the children below it but I want to publish the parent above as I said, linked up.
I've played with various code snippets posted here in this thread and other places I've found in my googling travels and I can't quite seem to find a way to do this reliably. It only needs to look at the Second Level children, the pages will never go deeper than that.
What ends up happening is I seem to have include the snippet in with the foreach statement which, as you probably know, will just repeat the parent name with each page because it's well, for each. Other snippets I've found will put up the overall parent or grandparent I guess, which ends up being Home or First Level Page.
Thanks for any insights, snippets, etc.
Basically I've got a site tree like so:
Home
->First Level Page
-->Second Level (Parent)
--->Second Level Child Page 1
--->Second Level Child Page 2
--->Second Level Child Page 3
I want to create an autonav custom template that lets me display the second level page (parent) at the top, linked to said parent, and then the children underneath as normal.
In the autonav settings I'm choosing "Look at pages below a specific page" which in my example would be "Second Level (Parent)".
I'm getting the children below it but I want to publish the parent above as I said, linked up.
I've played with various code snippets posted here in this thread and other places I've found in my googling travels and I can't quite seem to find a way to do this reliably. It only needs to look at the Second Level children, the pages will never go deeper than that.
What ends up happening is I seem to have include the snippet in with the foreach statement which, as you probably know, will just repeat the parent name with each page because it's well, for each. Other snippets I've found will put up the overall parent or grandparent I guess, which ends up being Home or First Level Page.
Thanks for any insights, snippets, etc.
Here's one way I found ... note that this displays the ultimate parent, so if you have a fourth level for example, it will still show the top second level parent.
The link is wrapped in an <h1> tag and class="ultiParent" is added so you can style as you want.
If you don't need the hard-coded auto-nav at the end, then you can just leave it out.
The link is wrapped in an <h1> tag and class="ultiParent" is added so you can style as you want.
If you don't need the hard-coded auto-nav at the end, then you can just leave it out.
<?php //Logic for getting displaying the ultimate parent $c = Page::getCurrentPage(); //If not on the home page if ($c->cID > 1) { $nh = Loader::helper('navigation'); $arrTrail = array_reverse($nh->getTrailToCollection($c)); $objHomePage = $arrTrail[0]; // Home page object; //If we're on a top-level page then our $arrTrail array will only have the home page object //so we test to see if its Page object exists $objTopPage = is_object($arrTrail[1]) && $arrTrail[1] instanceof Page && !$arrTrail[1]->error ? $arrTrail[1] : $c; //If we have a valid top page Page object we retrieve $title = $objTopPage->getCollectionName(); $pageHandle = $objTopPage->getCollectionHandle(); $url = $nh->getLinkToCollection($objTopPage);
Viewing 15 lines of 28 lines. View entire code block.
This works for a project I'm working on - Thanks for posting.
I ended up with the following, after playing with all the posted code.
This displays a parent on the children page or the actual page if its on the page(As long as its not the home page), I'm using this in a 5.7 version but should be ok in 5.6 looking at it, $ni->cObj might need adjusting?
This is displayed within the navigation items loop ($ni)
This displays a parent on the children page or the actual page if its on the page(As long as its not the home page), I'm using this in a 5.7 version but should be ok in 5.6 looking at it, $ni->cObj might need adjusting?
This is displayed within the navigation items loop ($ni)
$pIDArray = array(); foreach ($navItems as $ni){ $pIDArray[] = $ni->cObj->getCollectionParentID(); } $pID = $c->getCollectionParentID(); if(in_array($c->cID, $pIDArray)){ $pageId = $c->cID; $parentClasses = 'nav-selected'; }else{ $pageId = $c->getCollectionParentID(); $parentClasses = ''; } if ($pageId > 1) { $parentPage = Page::getById($pageId); echo '<li class="">';
Viewing 15 lines of 18 lines. View entire code block.
You can build some kind of breadcrumbs links to your parent pages:
<?php $level = 0; $current = $p = Page::getCurrentPage(); $tree = array(); while ($p->getCollectionParentID() >= HOME_CID){ array_push($tree, $p); $p = Page::getByID($p->getCollectionParentID()); } $tree = array_reverse($tree); if (isset($tree[$level])){ $parent = $tree[$level]; echo '<a href="'.View::URL($parent->getCollectionPath()).'">'.$parent->getCollectionName().'</a>'; } ?> /
Viewing 15 lines of 44 lines. View entire code block.
Thanks for this!
not so much with page list.