J
J
jacosjmacos2019-02-25 12:52:59
WordPress
jacosjmacos, 2019-02-25 12:52:59

How to attach ajax to ACF repeater pagination?

There is the following code:

<div id="galleryContainer" class="row gallery-content">
    
        <?php 
        if( get_query_var('page') ) {
          $page = get_query_var( 'page' );
        } else {
          $page = 1;
        }
         
        // Variables
        $row              = 0;
        $images_per_page  = 12; // How many images to display on each page
        $images           = get_field( 'gallery' );
        $total            = count( $images );
        $pages            = ceil( $total / $images_per_page );
        $min              = ( ( $page * $images_per_page ) - $images_per_page ) + 1;
        $max              = ( $min + $images_per_page ) - 1;
         
        // ACF Loop
        if( have_rows( 'gallery' ) ) : ?>
         
          <?php while( have_rows( 'gallery' ) ): the_row();
    
            $row++;
    
            // Ignore this image if $row is lower than $min
            if($row < $min) { continue; }
    
            // Stop loop completely if $row is higher than $max
            if($row > $max) { break; } ?>                     
    
            <?php $img_obj = get_sub_field( 'gallery_item' ); ?>
    
            <div class="gallery-content_photo" style="background: url('<?php echo $img_obj['sizes']['gallery']; ?>') no-repeat center/cover">
              <a data-fancybox="gallery" href="<?php echo $img_obj['sizes']['large']; ?>">
                <div></div>
              </a>
            </div>
    
          <?php endwhile; ?>
         
          
          <div class="col-12 gallery-content_pagi pagination d-flex justify-content-end">
            <?php  // Pagination
              echo paginate_links( array(
                'base' => get_permalink() . '%#%' . '/',
                'format' => '?page=%#%',
                'current' => $page,
                'total' => $pages,
                'prev_text'    => __('←'),
              'next_text'    => __('→')
              ) );
              ?>
          	</div>
         
        <?php else: ?>
         
          No images found
                 
        <?php endif; ?>
    
      </div>


The gallery is displayed, pagination works, but with a page reload. Is it possible to make it so that the transition to another page of pagination was without reloading (using Ajax)?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question