Created
April 18, 2014 16:37
-
-
Save ellenmva/11053195 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
function draw_gallery() { | |
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; | |
// $images = get_field('gallery'); | |
if( $images ): | |
?> | |
<div class="masonry row row-closed with-gutter" data-format="masonry"> | |
<?php // foreach( $images as $image ): | |
while( $row < $total ) : | |
// $row++; | |
$image = $images[$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; } ?> | |
<div class="span3 item"> | |
<div class="span-wrap pl-grid-wrap"> | |
<div class="item-img hidden-phone"> | |
<a href="<?php echo $image['sizes']['large']; ?>" rel="prettyPhoto[pp_gal]" title="<?php echo $image['caption']; ?>"><img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php echo $image['alt']; ?>" /></a> | |
</div> | |
<div class="item-img visible-phone"> | |
<img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php echo $image['alt']; ?>" /> | |
</div> | |
</div> | |
</div> | |
<?php endwhile; ?> | |
</div> | |
<div class="if-gallery-pagination"> | |
<?php | |
// Pagination | |
echo paginate_links( array( | |
'base' => get_permalink() . '%#%' . '/', | |
'current' => $page, | |
'total' => $pages | |
) ); | |
?> | |
</div> | |
<?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