Search code examples
concrete5concrete5-5.7concrete5-8.x

Concrete5 - avoiding duplication in multiple page lists on the same page


Apologies if the title is a bit confusing, but this is a problem specific to the CMS Concrete5.

I am working on a news/media related site, which consists of a main page which has 3 seperate pagelist blocks, with a layout as shown in the mockup attached.

enter image description here

For a page to appear in the featured pagelist (highlighted green), it needs to have the page attribute is_featured set to true. The 6 block pagelist (highlighted in red) is set to show ALL pages, including featured. Both pagelists are set to order by date, with the newest showing first.

The problem I'm having, is that when a content writer publishes a new page that is featured, I get immediate duplication with the same page listed in the top left of the 6 block pagelist. Given perhaps a day or so, as new 'non-featured' content gets added, the 'duplicated' page issue becomes less of a problem as it moves down the list, and onto the 2nd page (I have pagination on for the red block).

I'm using the standard Concrete5 pagelist block, and have custom templates which are just view.php files for the various lists (featured, 6 pages and sidebar list).

To remove the duplication, I tried adding some code in the view.php of the 6 pages template which would 'filter out' any featured page published in the last 24 hours. Whilst this does work, what I found was that I was then the 6 page pagelist would then show just 5 pages, and an empty gap for the 'filtered out' page.

My question is, is there a clean and better way of preventing duplication across pagelists? I don't want to have to set pagelists to only show certain categories (thus having no overlap whatsoever), but there must be a way to implement something that takes this particular issue into account?


Solution

  • In your "6 item pagelist" Page List block custom template, add the following code above your foreach ($pages as $page) {...} loop.

    $list->filterByIsFeatured(false);
    $list->setItemsPerPage(6);
    $pagination = $list->getPagination();
    $pages = $pagination->getCurrentPageResults();
    

    What this does is take the existing $list (Concrete\Core\Page\PageList object) and gets 6 non-featured pages from the page results. The options, sorting, and filtering set in the Page List block form should be preserved by reusing $list.

    The $list object is set here:
    https://github.com/concrete5/concrete5/blob/develop/concrete/blocks/page_list/controller.php#L225