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?

 
frz replied on at Permalink Reply
frz
you should be able to easily pull this off with the auto-nav if you just mess around with settings and look at preview.

not so much with page list.
walkerfx replied on at Permalink Reply
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'.
plschneide replied on at Permalink Reply
plschneide
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:
$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 -
echo $c->getCollectionName() 
echo $c->getCollectionAttributeValue('attribute_name')
plschneide replied on at Permalink Reply
plschneide
Is there no way to do this with concrete? An example would be awesome.
andrew replied on at Permalink Reply
andrew
Try

<?php
$page = Page::getByID($c->getCollectionParentID());
print $page->getCollectionName();
?>
plschneide replied on at Permalink Reply
plschneide
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.
ddrace replied on at Permalink Reply
ddrace
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:

$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.
ryan replied on at Permalink Reply
ryan
<?= View::URL($page->getCollectionPath()); ?>
ddrace replied on at Permalink Reply
ddrace
Just what I needed. Thanks!
uswebdesigner replied on at Permalink Reply
uswebdesigner
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.
uswebdesigner replied on at Permalink Reply
uswebdesigner
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,
uswebdesigner replied on at Permalink Reply
uswebdesigner
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,
uswebdesigner replied on at Permalink Reply
uswebdesigner
Found what I was looking for and wanted to share it.

http://icode4you.net/display-page-title-top-parent-menu-item-sub-pa...
aghouseh replied on at Permalink Reply
aghouseh
In the context of a page_list template, you can use this to get the parent page object.

$parent = Page::getByID($this->controller->cParentID);
SpatialAnomaly replied on at Permalink Reply
SpatialAnomaly
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.
keeasti replied on at Permalink Reply
keeasti
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.

<?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);
juddc replied on at Permalink Reply
juddc
This works for a project I'm working on - Thanks for posting.
TheRealSean replied on at Permalink Reply
TheRealSean
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)
$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="">';
marmaxkat replied on at Permalink Reply
marmaxkat
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>';
            }
            ?>
            /
tduncandesign replied on at Permalink Reply
tduncandesign
Thanks for this!