Building a Custom Page List in Concrete5

One of the best documented CMS in the wide range of Open Source systems is called Concrete5. While its market share is still minimal in comparison to the big systems like Drupal or Wordpress, it's still worth a closer look. In fact Concrete5 offers a really comfortable interface for editors and developers of smaller websites.

This CMS, as many others, comes with a broad selection of published plugins, which are (and that might be a problem for some of you) not always free and can in fact be pretty expensive. So developers with a smaller budget might want to take matters in their own hands with one feature or another. Recently I had to do this myself... with Page Lists.

Unfortunately the Page Lists provided by the GUI are not flexible enough for more complicated tasks. So it becomes clear quickly, that you will have to write some lines of code yourself. But thanks to the documentation this is a pretty easy thing to do. In the following paragraphs I will assume that you already have some basic knowledge of Concrete5. We would like to output a list of lectures. But only those taking place in the future.

First of all we will load a list of pages. At first this list is unspecific and unfiltered. Therefore we than filter this list by a certain type of page $ctHandle. The so called handle (lecture in our case) can be found in the dashboard.

Loader::model('page_list');

$pl = new PageList();
$pl->filterByCollectionTypeHandle('lecture');

Nevertheless, we would like to view only lecturers, which take place at some point in the future. So we will have to use another filter. Before we cleverly added a date attribute lecture_date to the page type lecture.

$pl->filterByAttribute('lecture_date', time(), '>');

But as it is, at the last minute the customer comes up with the idea, that lectures have to be filtered by topics. For example only lectures with Drupal as the main topic should be displayed. Of course we didn't add another attribute for this and the lectures have already been created. At this point we would have a problem, but thanks to Concrete5 the solution is again pretty simple. We can use full text filtering for example. The following code filters the page list by the given string value.

$pl->filterByKeywords('Drupal');

The query we built, Page Lists are actually just a way to define queries, can now be executed. The following command will return an array with all relevant entries. We can define how many items we want to query and on which offset we want to start.

$pages = $pl->get($itemsToGet = 100, $offset = 0);

Finally we can loop over the page list and output all necessary information. If you want to know more about Concrete5 itself and filtering in particular, check out the documentation.