Trying to get Auto-Nav to display current page + its subpages


I'm no longer in need of help trying to achieve this. I've decided to use a different way instead. Thank you all for your help regarding the matter though :).

Hello everyone,

I'm having difficulties with getting an Auto-Nav to work the way I want it to.

I've made a GlobalArea section and I've placed an Auto-Nav block inside it. What I'm trying to achieve is for it to display the current page it is on together with all of its subpages.

Example: (see attachment)

I got 4 pages on my website "Home | Gallery | Blog | About Me". Whenever a page is selected I want the autonav to display the current page it's on (Let's say we're on "About Me" currently) together with all of its subpages ("About Me | Contact Me | Third Subpage").

So if we were on the "About Me" page, the auto-nav would show "About Me | Contact Me | Third Subpage".

Is there any way to achieve this? Or am I going at it the wrong way?

I figured another possible option would be to create a subpage linking it to the parent page (creating an extra subpage called "About Me") or something. I'm a bit confused on how I should proceed.

In the end what I'm trying to achieve is to basically have a subnavigation beneath the main navigation that shows all of the subpages relative to one of the main navigation pages together with its current page.

So if the main navigation is "Home | Gallery | Blog | About Me" then I want the subnavigation to show "Current Page | Sub Page | Sub Page" (And possibly be completely blank if there are no subpages to display.)

I'm sure this is all a little vague, my apologies for that. I've added an image to help explain myself further. Please feel free to ask any questions that would allow me to elaborate in a way that would explain it better.

Kind regards and many thanks for your time and assistance,


1 Attachment

View Replies:
slafleche replied on at Permalink Reply
Check out this page:

If you're not hard coding your menu, all those options are available through concrete's interface.
Michaeldegreef replied on at Permalink Reply
Hello Slafleche,

The page you linked is interesting, I might hard-code the autonav for sections of my website in the template rather than making a GlobalArea.

I'm still uncertain as in how to proceed to get the desired autonav results, though.

I've successfully managed to hard code in the autonav into my template, but I am faced with the same options as through the concrete 5 interface when creating the autonav as a block (Which I'm having trouble with).

Perhaps the solution would be to create 2 autonavs next to eachother? Or perhaps there's a way to mimic the relationship of 'home' and it's subpages with the "top" setting to one of home's subpages?

(Current page sitemap is the following:

>About Me
>>Contact Me
>>Third Subpage

Whenever I select the "top" setting for page display it shows the following pages: "Home, Gallery, Blog, About Me". Which is the Home page + its subpages.
But whenever I select the "second_level" it only shows "temp1, temp2" or "Contact Me, Third Subpage" rather than those pages together with its parent page (Like with the "top" setting).)

Any ideas?



I think the best solution would be to find of a way to have the page automatically forward to a subpage...

Like if you have "About Me" - and you click it, you end up at the SUBPAGE of "About Me" (also called "About Me").

That way I can use second_level to show all of my desired pages in the autonav.
slafleche replied on at Permalink Reply
Leave displayPages to top, but also set displaySubPages to All.
If there are any pages you don't want included, you can always change their properties (in the custom attribute tab), to not be included in nav.

I suggest rereading the page I sent you again. There's a lot of neat functions, including limiting the sub page levels.

Also, don't be afraid to try out all the options! Your site won't blow up, i promise.
Michaeldegreef replied on at Permalink Reply 1 Attachment
Thanks for your reply Slafleche,

I've been fiddling around the options and settings a bit before, taking the page you linked as my guide. But whatever option I tried I couldn't get what I tried to achieve.

Closest I got was:
   $nav = BlockType::getByHandle('autonav');
   $nav->controller->orderBy = 'display_asc';
   $nav->controller->displayPages = 'second_level';
   $nav->controller->displaySubPages = 'none';

Which would result in showing all of the subpages (But not the current top level page).

I've also tried what you suggested, setting the displayPages to 'top', and the displaySubPages to 'all'
   $nav = BlockType::getByHandle('autonav');
   $nav->controller->orderBy = 'display_asc';
   $nav->controller->displayPages = 'top';
   $nav->controller->displaySubPages = 'all';

unfortunately that resulted in showing all of the top level pages (home, blog, aboutme etc.), rather than the current top level page and its subpages.

I've also fiddled around with other settings, but in every case I always ended up with either all of the top level pages or none of the top level pages (While I only wish to display the top level page of the page it's on).

So I'm afraid I'm still at a loss.

PS: I've attached another image to visually represent what I'm trying to achieve.



I'm no longer in need of help trying to achieve this. I've decided to use a different way instead. Thank you all for your help regarding the matter though :).
peteallen replied on at Permalink Reply
For anyone who may need something like this in the future, then I have found using the following code will display the current page name and its subpages, may not be the best way but it seems to work for me!

// Get current page name
$page_name = $c->getCollectionName();
// Get parent page name and url
$parent = Page::getByID($c->getCollectionParentID()); 
$parent_name = $parent->getCollectionName(); 
$parent_url = View::URL($parent->getCollectionPath());
if($parent_name == 'Home') {
    echo '<a href="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '">' . $page_name . '</a>'; 
} else {
    echo '<a href="' . $parent_url . '">' . $parent_name . '</a>'; 
// Set autonav block to display all sub pages of current page
$section = BlockType::getByHandle('autonav');
$section->controller->orderBy = 'display_asc';
SteamSynthetic replied on at Permalink Reply
Im posting this here only because the google search results/concrete5 forum results for what I was trying to find were not the answer I was looking for.

This is something that worked for me if someone wanted to put it into the page template, and not into an autonav. Such as a page title.

   $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 $parent->getCollectionName(); 

Basically, in your theme, it will check if its the homepage, and also check if its a top level navigation page. If it is, it displays the title. If its a 2nd level navigation page, it displays the parent title.

It works in a situation like this:
-Subcategory 1
-Subcategory 2
Where as the subcategory page will still display "Products" as the main title, then you can echo out the current page name as a subtitle.
jamils replied on at Permalink Reply
I realise that the original poster has found a way around this, but for anyone who is trying to do this - and I suspect there are many, because it's the best way to avoid using a frivolous 'landing page' for each main menu section - there is a free add-on in the Marketplace:

It gives the option to automatically jump to the first child page.

It's a bit of a lifesaver. Kudos to MrNiceGaius.