Pagination not working with nested loops

I’m showing a specific news article, and all the images connected to that news via an ACF Relationship field. The images are in a separate CPT called images.

The loops correctly show 5 images, but the pagination simply says Page 1 of 1. Is there any way to tell the pagination tag which loop it’s meant to work on?

<Loop type=news field=name field_value=lost-dog>
  <Field title />
  <Loop acf_relationship="news_image" paged=2>
       <Field image />
  </Loop>
  <PaginateButtons />
  <PaginateFields>
    Page <Field current_page /> of <Field total_pages />
  </PaginateFields>
</Loop>

Another problem with pagination is that say page 1 is very long and page 2 is short. Since the buttons are at the bottom, when you go from page 1 to page 2 the browser tries to show where the bottom of page 1 was, which puts you way further down on page 2 than you should be.

It would be nice if the buttons could be moved to the top of the loop.

There isn’t currently a solution to this as far as I’m aware, but we’ll look into whether it would make sense/be feasible to allow specifying context to pagination somehow (would definitely be nice to be able to place pagination before a loop).

I might try using a slider for the images instead as a workaround:

<Slider items=2>
 <Loop acf_relationship="news_image">
       <Slide><Field image /></Slide>
   </Loop>
</Slider>

Here’s documentation for the slider module

Thanks much for the slider example. I wouldn’t have thought that.

Perhaps the pagination code could be inside the loop, either at the top or bottom (easy for me to say).

1 Like