Last active
December 14, 2015 01:19
-
-
Save johnbhartley/5005299 to your computer and use it in GitHub Desktop.
Public MG Pagination
This file contains hidden or 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 | |
//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, '← 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 →' ); ?></span> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// 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, '→' ); ?></span>