Add to Page List length when it includes current page

Hello all,

I have a blog with pages that include a custom Page List block showing the 5 most recent entries in the sidebar. I want don’t want to show the current page in the list if it is one of the most recent entries. However, I always want the Page List to have 5 entries. Currently, if the page is excluded from the list, I only have 4 entries.

I am able to exclude the current page from the list using a custom template View file, however, testing for the duplication while building the $pages array needs to take place in the Controller file, as I need to adjust the $pages array length before sending the data to the View file.

I would really appreciate any help with this.


I think the easiest would be to set your page list to fetch 6 pages like that if the current page is included you still have 5 pages and if not, you just don’t display the 6th one.

That’s much simpler than having to override the controller.

1 Like

@mnakalay is correct. The only way to do it is to override the controller. I ran into this years ago, where one page would be missing in results just as you describe. In the end I built my own Page List package that handles excluding current page out of the box. No more messing around with templates etc to accomplish this! There’s a WHOLE LOT more built into it than just the exclude page functionality. There’s also a handfull of tweaks and new features about to be released. Have a look here if you’re interested: Enlil Page List - Concrete CMS

Thanks guys. @mnakalay, your suggestion is how I am currently handling it (with CSS). I was hoping for something more elegant, but I guess if it works…

It seems to me that a simple option to not include the current page in the Page List should be built in to the native block.

Thank you @enlil for your input, and the link. I will definitely check out your Add-On.

1 Like

I cosign the need for it in the core block as well… I should probably get around to doing that Pull Request one of these days!

1 Like

@vergedesign why use CSS? You have a loop going through the array of pages. For each page compare the cID to the current page’s cID if it’s the same don’t output it and let the loop run its course. Otherwise, if you reach the last element of the array and still didn’t find the current page, just exit the loop and don’t output the last element.

@vergedesign @enlil feel free to add it as a feature request to the Github issues section for Concrete - somebody else might pick it up and include it in the meantime :+1: Issues · concretecms/concretecms · GitHub

@vergedesign thanks for the good question - if you want to mark the response that helped you as the “Solution” that’s super helpful for us. Thanks!

That would be too easy, I guess :slight_smile:

@EvanCooper @vergedesign Page List Block Exclude Current Page & php8 undefined fix by ccmEnlil · Pull Request #10678 · concretecms/concretecms · GitHub

@mnakalay Those tricks are nice, until you start using pagination. This PR has been back of my mind for YEARS now :slight_smile:

@enlil absolutely and totally agree with you.

I was, however, answering to the specific situation originally described in this post and with only 5 links to show, pagination is not really going to be a problem.

As for the general usability of the page list block, yes I highly agree, it could do with some improvement and your package brings much needed functionality to it.

Quite right… no issue with pagination in this case, and exiting the loop after 5 successes was easy enough to implement in the custom template.

The only oddity is explaining to my client why they need to add 1 more item in the Page List dialogue than they actually want.


Very cool, and thank you for the work put in! The c5 community is incredible, and it is one of the many reasons why I have continued to use c5.

I incorporated your PR into my c5 v9 local test site, and while it works when I publish the page, it doesn’t seem to retain the settings when I return to the page. I tried it a number of times, and the setting isn’t sticky.

Also, for consistency, you might want to add a “.” to the end of the checkbox text in the page_list_form.php file, as all of the others in the list have one.

@vergedesign You’re right on getting it working. Just visit /dashboard/blocks/types, choose Page List Block, and Refresh it to update the database!!

1 Like

Yes indeed! So cool, and good to know that tip!

PR has been merged. “Exclude Current Page” will be available in v9.1.2