wp/wp-content/themes/twentytwelve/image.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * The template for displaying image attachments
     3  * The template for displaying image attachments
     4  *
     4  *
     5  * @link http://codex.wordpress.org/Template_Hierarchy
     5  * @link https://codex.wordpress.org/Template_Hierarchy
     6  *
     6  *
     7  * @package WordPress
     7  * @package WordPress
     8  * @subpackage Twenty_Twelve
     8  * @subpackage Twenty_Twelve
     9  * @since Twenty Twelve 1.0
     9  * @since Twenty Twelve 1.0
    10  */
    10  */
    56 foreach ( $attachments as $k => $attachment ) :
    56 foreach ( $attachments as $k => $attachment ) :
    57 	if ( $attachment->ID == $post->ID )
    57 	if ( $attachment->ID == $post->ID )
    58 		break;
    58 		break;
    59 endforeach;
    59 endforeach;
    60 
    60 
    61 $k++;
       
    62 // If there is more than 1 attachment in a gallery
    61 // If there is more than 1 attachment in a gallery
    63 if ( count( $attachments ) > 1 ) :
    62 if ( count( $attachments ) > 1 ) :
       
    63 	$k++;
    64 	if ( isset( $attachments[ $k ] ) ) :
    64 	if ( isset( $attachments[ $k ] ) ) :
    65 		// get the URL of the next image attachment
    65 		// get the URL of the next image attachment
    66 		$next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
    66 		$next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
    67 	else :
    67 	else :
    68 		// or get the URL of the first image attachment
    68 		// or get the URL of the first image attachment
    69 		$next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
    69 		$next_attachment_url = get_attachment_link( $attachments[0]->ID );
    70 	endif;
    70 	endif;
    71 else :
    71 else :
    72 	// or, if there's only 1 image, get the URL of the image
    72 	// or, if there's only 1 image, get the URL of the image
    73 	$next_attachment_url = wp_get_attachment_url();
    73 	$next_attachment_url = wp_get_attachment_url();
    74 endif;
    74 endif;