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 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.
@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.
@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.
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.
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.