Listing the last 5 pages

Permalink
Hello there;

With the following code, I list the subpages of a particular page. However, this code lists all the sub-pages. But what I want is to list the last 5 sub-pages. How can I limit the number of pages listed?

<?php
// 1. Let's make our auxiliary classes.
$th = Core::make('helper/text');
$ih = Core::make('helper/image');
$dh = Core::make('helper/date');
// 2. Let's get the block here.
$nbo_bo = BlockType::getByHandle('autonav');
$nbo = $nbo_bo->controller;
$nbo->orderBy = 'chrono_desc';
$nbo->displayPages = 'custom';
$nbo->displayPagesCID = Page::getByPath('/pagename')->getCollectionID();
$nbo->displaySubPages = 'all';
$nbo->displaySubPageLevels = 'all';
// 3. Let's start creating the screen display.
$nbo_items = $nbo->getNavItems();

 
hutman replied on at Permalink Best Answer Reply
hutman
You want to use a PageList, not an autonav.

use Page;
use PageList;
$cParentID = Page::getByPath('/pagename')->getCollectionID();
$list = new PageList();
$list->filterByParentID($cParentID);
$list->sortByDisplayOrderDescending();
$pagination = $list->getPagination();
$pagination->setMaxPerPage(1);
$pageResults = $pagination->getCurrentPageResults();