diff --git a/attachment.php b/attachment.php index 6f4f103..3926d6c 100644 --- a/attachment.php +++ b/attachment.php @@ -27,14 +27,17 @@ function cfct_get_adjacent_image_link($prev = true) { $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 ) + foreach ( $attachments as $k => $attachment ) { + if ( $attachment->ID == $post->ID ) { break; + } + $k = $prev ? $k - 1 : $k + 1; if ( isset($attachments[$k]) ) return wp_get_attachment_link($attachments[$k]->ID, 'thumbnail', true); + } } /**