go to grandchild page

Permalink
i was able to dig up "replace_link_with_first_in_nav" which worked well for the one part of the site im doing. however, i'm looking to take this one step further. i need the page to link to the grandchild element.

i.e...

professionals
-principals
--name (professionals should bypass principals and go to this link)

i assume i need to set up another page attribute and modify my autonav template to allow for this functionality.

 
jhart replied on at Permalink Reply
just bumping... really could use a solution for this. really appreciate any help.
Remo replied on at Permalink Reply
Remo
not sure if it works, didn't test it.

it's ugly but you can check the attribute twice..

if ($_c->getCollectionAttributeValue('replace_link_with_first_in_nav')) { 
                $subPage = $_c->getFirstChild(); 
                if ($subPage instanceof Page) { 
                    $pageLink = $nh->getLinkToCollection($subPage); 
                 if ($subPage ->getCollectionAttributeValue('replace_link_with_first_in_nav')) { 
                    $subSubPage = $subPage ->getFirstChild(); 
                  if ($subSubPage  instanceof Page) { 
                      $pageLink = $nh->getLinkToCollection($subSubPage ); 
                  } 
              } 
                } 
            }
jhart replied on at Permalink Reply
may be ugly. but it works :)
SteveAtParadigm replied on at Permalink Reply
This just what I need! But where does that code go?
SteveAtParadigm replied on at Permalink Reply
OK, I found it in view.php for the core autonav block. Taking it one step further, you can add a page attribute as a dropdown to select the descendant to which the menu should link. Its working for me quite well :)

Use these steps:
1) Create a new page attribute as a 'select' dropdown with the handle 'replace_link_with_descendant'. Add these values:
'1st Child'
'1st Grandchild'
'1st Great Grandchild'

2) Backup concrete/concrete/blocks/autonav/view.php, then find the this code:
if ($_c->getCollectionAttributeValue('replace_link_with_first_in_nav')) {
   $subPage = $_c->getFirstChild();
   if ($subPage instanceof Page) {
      $pageLink = $nh->getLinkToCollection($subPage);
   }
}


and add this NEW code underneath:
if ($_c->getCollectionAttributeValue('replace_link_with_descendant') == '1st Child') {
   $childPage = $_c->getFirstChild();
   if ($childPage instanceof Page) {
      $pageLink = $nh->getLinkToCollection($childPage);
   }
} else if ($_c->getCollectionAttributeValue('replace_link_with_descendant') == '1st Grandchild') { 
   $childPage = $_c->getFirstChild(); 
   if ($childPage instanceof Page) { 
      $grandChildPage = $childPage ->getFirstChild(); 
      if ($grandChildPage  instanceof Page) { 
         $pageLink = $nh->getLinkToCollection($grandChildPage); 
      } 
   } 
}  else if ($_c->getCollectionAttributeValue('replace_link_with_descendant') == '1st Great Grandchild') { 
   $childPage = $_c->getFirstChild();


Step 3) Add your custom attribute to an individual page or add it to a page type default.

Goodluck!
stretchrt replied on at Permalink Reply
stretchrt
Thanks Steve - just what I was looking for - except I can't get it to work! It works for a page and it's first child that appear in the same autonav - but I can't get it to do the grandchild of a top level page where the top page is in the header autonav and the subpage is in the sidebar autonav - it won't do first child or grandchild in that instance - not sure why!
Steff replied on at Permalink Reply
Steff
That's funny. I was looking for the same thing too.

Thank you Remo for your solution.