Skip to content

Instantly share code, notes, and snippets.

@johnbhartley
Last active December 14, 2015 01:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbhartley/5005299 to your computer and use it in GitHub Desktop.
Save johnbhartley/5005299 to your computer and use it in GitHub Desktop.
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
Copy link

// 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