As I pointed in the comments, if for example you’re displaying 9 posts per page, which means there would be 3 gallery images shown per page, and you want page #1 to show images 1-3, page #2 to show images 4-6, and so on, then you would want to paginate the gallery images:
// the number 3 below is the position where the image is to be added to
$paged = max( 1, get_query_var( 'paged' ) ); // get the current page number
$per_page = floor( max( 1, get_query_var( 'posts_per_page' ) ) / 3 );
$counter = 1;
$img_ct = ( $paged - 1 ) * $per_page; // start showing images of this index
And that would replace this part:
$counter = 1;
$img_ct = 0;
Also, you should use if ( ! empty( $images ) )
instead of just if ( $images )
.
Related Posts:
- WordPress category & taxonomy loop with pagination
- Use ACF Category Image for all Taxonomy Archive Views
- Attachment Metadata inside of Loop
- How to fix pagination for custom loops?
- Split Content and Gallery
- Pagination not working on home page
- How to get the first image gallery of a product in woocommerce in a loop
- ACF Repeater loops and resets – where is the reset_rows() documentation? [closed]
- How do I prevent one of two multiple loops from repeating on a second page?
- Two custom loops, pagination, offset
- Remove comma from last item output from loop
- Previous and Next Post link doesn’t work
- Pagination adding extra posts only on page 2
- Get posts that matches specific terms of multiple custom taxonomies
- Filtering posts by multiple taxonomies
- Using get_term() in functions.php results in Invalid taxonomy error
- multiple loops with pagination on the same page
- Enable infinite scroll on single.php [closed]
- How to paginate this custom loop? [duplicate]
- Make a custom loop inside single.php with pagination
- Why do I get `Call to a member function have_posts() on a non-object `? [closed]
- Pagination gives extra page with no results
- Get Pagination (WP-PageNavi) not to work
- the_content() seems to block my ACF-code
- How can I modify the loop from a plugin without wiping out other filters?
- How to get an array of years from all of the search results, and use it to filter by year the paginated loop?
- Complex query and posts pagination
- How to return only one instance of each, from the entire loop
- Why only one post (and no pagination) on this variation of the loop?
- Displaying terms based on loop posts?
- I write simple wordpress loop for taxonomy.php file but don’t show result
- Split loop to load WordPress gallery into Bootstrap modal and carousel
- How do I go about looping through a advanced custom field on a particular page inside of another page
- Calling & display certain product category loop and pagination on the homepage
- Using an ACF field from a page within a post loop?
- Pagination for multiple loops
- How to fix pagination for custom loops?
- How can I paginate this?
- How to fix pagination for custom loops?
- Pagination – works on local but not live dev!
- How do I paginate a get_posts() request inside another page loop (Paginating childpages)
- ACF custom field in [closed]
- ACF – add a group inside a repeater [closed]
- While loop with bootstrap [closed]
- How to exclude or filter password protected posts when using next_post_link() previous_post_link
- Trying to get property of non-object in shortocde
- How to append a query string to pagination?
- How to create a multidimensional array with multiple loops
- How do I get my loop.php to properly paginate?
- First archive page with a few posts
- display post format text in loop
- Display name of taxonomy once
- Loop through ACF taxonomies and output associated posts
- Pagination on custom post type on front-page.php
- I have broke my pagination, same posts on all pages (index.php)
- Frontpage pagination by week
- Blank content php code not parsing advanced custom fields gallery add-on [closed]
- How can this multiple loop have pagination as described?
- Display more than 10 posts on author.php file
- static page with multiple loops breaks post pagination
- How to use this $tax_selection variable in this custom loop?
- Pagination for two loops
- Avoid WP_Query’s duplicate posts with taxonomies
- Skip 5 latest post while paging?
- Why does my WP_Query pagination on a custom page.php only loads the homepage?
- ACF: display custom filed of CPT into the loop
- Need to while loop and display contents in the subfield of a group field given by ACF
- Add Search and Filter functionality to custom loop
- Get gallery in loop through ajax
- How to insert content before pagination in loop?
- Pagination on a underscore custom theme
- WordPress multiple loops with default pagination
- dispaly all hierarchical post types from a taxonomy
- Split Content and Gallery
- Return only one post format in index.php [duplicate]
- How to fix pagination for custom loops?
- Style first 3 posts differently and use a 2nd loop to get rest of posts / offset and pagination broken
- Custom loop not working in singular.php, working in other pages
- Loop shows post 5 times in a query
- Alternative layout the loop
- ACF field not appearing correctly in loop
- Creating a archive for taxonomy terms, not the term results
- How to fix pagination for custom loops?
- Adding pagination to WP_Query [duplicate]
- Can’t see custom field after the Loop [closed]
- How to fix pagination for custom loops?
- Why is my pagination showing up?
- Change the way wordpress outputs images or image galleries
- Displaying posts limit: can’t get pagination to display [duplicate]
- Paged homepage – requirements?
- Home page loop with pagination problem
- WooCommerce custom loop pagination on front page
- While loop inside another while loop
- posts_nav_link() not working on index.php
- ACF loops false value with repeater and checkbox
- repeating posts on 2nd page to posts
- Limitless amount of posts in custom archive page
- Same posts within a paginated page
- Multiple loop with pagination in same page
- Insert multiple custom components after x-number of posts