Auto nav display X items
Permalink
HI with page list its possible to set the number of items that are displayed, however for various reason i need to use the autonav block, is there a way, even if it involves hardcoding it into the block, to limit the number of pages it shows?
I'm using this code in my footer to show some pages, however I only want to show the most recent 5 pages, not all 34!
Thanks in advance
I'm using this code in my footer to show some pages, however I only want to show the most recent 5 pages, not all 34!
<?php $bt_main = BlockType::getByHandle('autonav'); $bt_main->controller->displayPages = 'custom'; $bt_main->controller->displayPagesCID = '125'; $bt_main->controller->orderBy = 'chrono_desc'; $bt_main->controller->displaySubPages = 'none'; $bt_main->render('view'); ?>
Thanks in advance
Hi Thanks for that, it looks like it would be the answer… but…
there is no $i in the code…. the foreach refers to $navitems and $ni, i've tried a nnumber of combinations of these in place of $i with no luck… what am i missing?
Thanks
there is no $i in the code…. the foreach refers to $navitems and $ni, i've tried a nnumber of combinations of these in place of $i with no luck… what am i missing?
Thanks
//*** Step 2 of 2: Output menu HTML ***/ echo '<ul class="nav">'; //opens the top-level menu if ($i > 10) { break; } $i++; foreach ($navItems as $ni) { echo '<li class="' . $ni->classes . '">'; //opens a nav item echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>'; if ($ni->hasSubmenu) { echo '<ul>'; //opens a dropdown sub-menu } else { echo '</li>'; //closes a nav item echo str_repeat('</ul></li>', $ni->subDepth); //closes dropdown sub-menu(s) and their top-level nav item(s) } } echo '</ul>'; //closes the top-level menu
Yep - Had to slightly rework things - but this should hopefully do the trick:
Auto nav custom template file also attached (you'll need to change the file extension to '.php').
Hope that helps!
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $navItems = $controller->getNavItems(); $i = 0; foreach ($navItems as $ni) { $classes = array(); if ($ni->isCurrent) { $classes[] = 'nav-selected'; } if ($ni->inPath) { $classes[] = 'nav-path-selected'; } $ni->classes = implode(" ", $classes); } //*** Step 2 of 2: Output menu HTML ***/ echo '<ul class="nav">'; //opens the top-level menu
Viewing 15 lines of 23 lines. View entire code block.
Auto nav custom template file also attached (you'll need to change the file extension to '.php').
Hope that helps!
Perfik! thanks
You would need to make a custom template (copy
/concrete/blocks/autonav/view.php to /blocks/autonav/view.php), and add a
counter before the "foreach" loop (the one at the bottom of the
template that outputs the HTML), like "$i = 0;" (without the quotes).
Then inside the foreach loop, use some code like "$if ($i > 10) {
break; } $i++;" (without the quotes) to stop looping when you hit the
10th menu item.
Source:
http://c5blog.jordanlev.com/blog/2012/04/hard-coded-autonav-options...
See how you get on!