listing all pages alphabetically by title
Posted: Thu Jan 31, 2019 5:06 pm
i'm using the code from the manual to list all pages, but i'd like to sort them alphabetically.
using sort() on the array sorts it alphabetically by URL path (i believe). how can i sort by title?
using sort() on the array sorts it alphabetically by URL path (i believe). how can i sort by title?
Code: Select all
<?php
// Page number of the paginator, the first page is 1
$pageNumber = 1;
// The value -1 tell to Bludit to returns all the pages on the system
$numberOfItems = -1;
// Only get the pages with the satus published
$onlyPublished = true;
// Get the list of keys of pages
$items = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
//alphabetical
sort($items);
foreach ($items as $key) {
// buildPage function returns a Page-Object
$page2 = buildPage($key);
// Print the page title
?>
<li class="nav-item">
<a class="nav-link" href="<?php echo $page2->permalink(); ?>"><?php echo $page2->title(); ?></a>
</li>
<?php } ?>