What's in this article
What's in this article
There are many reasons why you may want to hard-code a pagelist rather than use a block. The most common reason I find is when I want to make an ajax pagelist. I will hard-code the pagelist into a tools file and call that tools file from my javascript ajax function.
This code is for Concrete5 v5.7+.
To embed the pagelist, first load the navigation helper:
$nh = Loader::helper('navigation');
Then we add the following, notice in this case we are filtering the results so that we show blog pages - i.e. pages which use the blog_page pagetype:
$pl = new \Concrete\Core\Page\PageList();
$pl->filterByPageTypeHandle('blog_page');
$pages = $pl->getResults();
Then we need a foreach loop to go through the results and actually write out pages:
foreach($pages as $page) {
$title = $page->getCollectionName();
$intro = htmlentities($page->getCollectionDescription());
$url = $nh->getCollectionURL($page);
echo $title;
}
In this example, we are just writing out the title of each page.
So our complete pagelist example looks like this:
$nh = Loader::helper('navigation');
$pl = new \Concrete\Core\Page\PageList();
$pl->filterByPageTypeHandle('blog_page');
$pages = $pl->getResults();
foreach($pages as $page) {
$title = $page->getCollectionName();
$intro = htmlentities($page->getCollectionDescription());
$url = $nh->getCollectionURL($page);
echo $title;
}
Easy isn't it?
Of course, you can do much more. Here are some of the filters available:
$pl->filterByPageTypeHandle('blog_page');
$pl->filterByPath('/recent-work', true);
$pl->filterByKeywords();
See more filters at /concrete/src/Page/PageList.php
Adjustments for v5.6+
For version 5.6 of Concrete5 you want to adjust the above code to have the following lines:
Loader::model('page_list');
$pl = new PageList();
$pages = $pl->get();
Article by David Reeder. LinkedIn Profile: https://www.linkedin.com/in/david-e-reeder/
Related Articles
29 August 2025
A while ago, Concrete CMS introduced folders as a way of organising related files. What if we could make a block that lists all the files in a folder… Read more
09 July 2025
Concrete CMS comes with very flexible, granular user permissions. When setting permissions to advanced, we can give users access to edit as much or… Read more
16 October 2024
Caching is essential for making web pages load fast, but you also need an acceptable level of control to avoid other issues. Concrete CMS features a… Read more
Keep up to date
Subscribe to receive occasional email newsletters from us.