Jump to content

Images pagination


Recommended Posts

On 6/16/2020 at 10:11 PM, Violet said:

? My question is, I'm wondering if there is (or could one day be) a function in the ProcessWire API that as a one line command, converts images on a page to a (temporary) page array, each element of which contains one image? ?The idea being that the resultant page array could be used directly for pagination purposes just like any other page array, which is handy for image gallery situations such as this. It seems like it's a common issue people are facing.

@Violet I wonder if you missed the well explained solution of gingebaker here in this thread:

Isn't the PaginatedArray class just what you are looking for?

  • Like 1
Link to comment
Share on other sites

Thank you @TheMick- it looks like I did miss that. It sounds like it would work, although I admit it's a bit beyond me - I'm not an experienced programmer. I was hoping to avoid writing functions. I can't remember what I did in the end on my particular project - I think I just decided to use a reasonable number of images that would look OK on 1 page and didn't bother paginating them. If I need to go back to that I will definitely take another careful look at the solution you mentioned and implement it for my situation.

Thank you for bringing this to my attention, as other people who come across this thread will now be able to direct themselves to the solution you mentioned ?

  • Like 1
Link to comment
Share on other sites

  • 9 months later...

Since it seems that all irregular pagination use roads lead to this thread, I just wanted to point out that the following enables pagination for a regular PHP array (all the other examples I saw are for PageFiles or PageImages-type arrays). My context of use here is a search results screen where I needed to dump a PageArray out to process additional ranking criteria, resulting in an array named $listings below.

$items_per_page = 10;
$start = ($input->pageNum - 1) * $items_per_page;
$total = count($listings);
$listed = array_slice($listings, $start, $items_per_page); // Key difference
$a = new PageArray();
foreach($listed as $listing) $a->add(new Page());

echo $a->renderPager();

If you get a complaint about PageArray, it's likely because you haven't declared the ProcessWire namespace in your template.

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...