Created
November 29, 2017 07:21
-
-
Save Roshanb54/55475ae085627e2c1b41c2da6e1cebe2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Paginate Advanced Custom Field repeater | |
*/ | |
if( get_query_var('page') ) { | |
$page = get_query_var( 'page' ); | |
} else { | |
$page = 1; | |
} | |
// Variables | |
$row = 0; | |
$repeater_field_per_page = 10; // How many "repeater fields" to display on each page | |
$field_name = get_field( 'Field Name Here' ); | |
$total = count( $field_name ); | |
$pages = ceil( $total / $repeater_field_per_page ); | |
$min = ( ( $page * $repeater_field_per_page ) - $repeater_field_per_page ) + 1; | |
$max = ( $min + $repeater_field_per_page ) - 1; | |
// ACF Loop | |
if( have_rows( 'Field Name Here' ) ) : ?> | |
<?php while( have_rows( 'Field Name Here' ) ): 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 $subfield_obj = get_sub_field( 'Sub field name here' ); ?> | |
<a href="<?php echo $subfield_obj['sizes']['large']; ?>"> //if this is the image field | |
<img src="<?php echo $subfield_obj['sizes']['thumbnail']; ?>" alt=""> | |
</a> | |
<?php endwhile; | |
// Pagination | |
echo paginate_links( array( | |
'base' => get_permalink() . '%#%' . '/', | |
'format' => '?page=%#%', | |
'current' => $page, | |
'total' => $pages | |
) ); | |
?> | |
<?php else: ?> | |
No images found | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment