Skip to content

Instantly share code, notes, and snippets.

@johnbhartley johnbhartley/gist:5005299
Last active Dec 14, 2015

Embed
What would you like to do?
Public MG Pagination
<?php
//grabbed from image.php in TwentyTwelve...credit where credit's due
/**
* Grab the IDs of all the image attachments in a gallery so we can get the URL of the next adjacent image in a gallery,
* or the first image (if we're looking at the last image in a gallery), or, in a gallery of one, just the link to that image file
*/
$attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
foreach ( $attachments as $k => $attachment ) :
if ( $attachment->ID == $post->ID )
break;
endforeach;
$k++;
// If there is more than 1 attachment in a gallery
if ( count( $attachments ) > 1 ) {
// total image count
$att_count = count( $attachments );
}
?>
<?php
//display the 'full' image
echo wp_get_attachment_image( $post->ID, 'full' );
?>
<div class="entry-caption">
<span class="previous-image"><?php previous_image_link( false, '&larr; Previous' ); ?></span>
<?php
// first method...taken from twenty twelve
// $k is the number in the sequence and $att_count is the total
echo $k .' / ' . $att_count;
// the URL for the parent gallery
$gallery_url = get_permalink( $post->post_parent );
echo '<a href="'.$gallery_url.'">back to gallery</a>';
// end first method
// Wes Linda Method
// the URL for the parent gallery
$parent = get_post_field( 'post_parent', $id);
$link = get_permalink($parent);
echo '<a href="'. $link .'">gallery</a>';
// end WLM
?>
<span class="next-image"><?php next_image_link( false, 'Next &rarr;' ); ?></span>
</div>
@weslinda

This comment has been minimized.

Copy link

weslinda commented Feb 21, 2013

// the URL for the parent gallery $parent = get_post_field( 'post_parent', $id); $link = get_permalink($parent); echo '<a href="'. $link .'">gallery</a>'; ?> <span class="next-image"><?php next_image_link( false, '&rarr;' ); ?></span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.