wp/wp-content/themes/twentytwelve/image.php
changeset 8 c7c34916027a
parent 7 cf61fcea0001
child 9 177826044cd9
equal deleted inserted replaced
7:cf61fcea0001 8:c7c34916027a
     1 <?php
       
     2 /**
       
     3  * The template for displaying image attachments
       
     4  *
       
     5  * @link https://codex.wordpress.org/Template_Hierarchy
       
     6  *
       
     7  * @package WordPress
       
     8  * @subpackage Twenty_Twelve
       
     9  * @since Twenty Twelve 1.0
       
    10  */
       
    11 
       
    12 get_header(); ?>
       
    13 
       
    14 	<div id="primary" class="site-content">
       
    15 		<div id="content" role="main">
       
    16 
       
    17 		<?php
       
    18 		while ( have_posts() ) :
       
    19 			the_post();
       
    20 ?>
       
    21 
       
    22 				<article id="post-<?php the_ID(); ?>" <?php post_class( 'image-attachment' ); ?>>
       
    23 					<header class="entry-header">
       
    24 						<h1 class="entry-title"><?php the_title(); ?></h1>
       
    25 
       
    26 						<footer class="entry-meta">
       
    27 							<?php
       
    28 								$metadata = wp_get_attachment_metadata();
       
    29 								printf(
       
    30 									__( '<span class="meta-prep meta-prep-entry-date">Published </span> <span class="entry-date"><time class="entry-date" datetime="%1$s">%2$s</time></span> at <a href="%3$s" title="Link to full-size image">%4$s &times; %5$s</a> in <a href="%6$s" title="Return to %7$s" rel="gallery">%8$s</a>.', 'twentytwelve' ),
       
    31 									esc_attr( get_the_date( 'c' ) ),
       
    32 									esc_html( get_the_date() ),
       
    33 									esc_url( wp_get_attachment_url() ),
       
    34 									$metadata['width'],
       
    35 									$metadata['height'],
       
    36 									esc_url( get_permalink( $post->post_parent ) ),
       
    37 									esc_attr( strip_tags( get_the_title( $post->post_parent ) ) ),
       
    38 									get_the_title( $post->post_parent )
       
    39 								);
       
    40 							?>
       
    41 							<?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
       
    42 						</footer><!-- .entry-meta -->
       
    43 
       
    44 						<nav id="image-navigation" class="navigation" role="navigation">
       
    45 							<span class="previous-image"><?php previous_image_link( false, __( '&larr; Previous', 'twentytwelve' ) ); ?></span>
       
    46 							<span class="next-image"><?php next_image_link( false, __( 'Next &rarr;', 'twentytwelve' ) ); ?></span>
       
    47 						</nav><!-- #image-navigation -->
       
    48 					</header><!-- .entry-header -->
       
    49 
       
    50 					<div class="entry-content">
       
    51 
       
    52 						<div class="entry-attachment">
       
    53 							<div class="attachment">
       
    54 <?php
       
    55 /*
       
    56  * 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,
       
    57  * 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
       
    58  */
       
    59 $attachments = array_values(
       
    60 	get_children(
       
    61 		array(
       
    62 			'post_parent'    => $post->post_parent,
       
    63 			'post_status'    => 'inherit',
       
    64 			'post_type'      => 'attachment',
       
    65 			'post_mime_type' => 'image',
       
    66 			'order'          => 'ASC',
       
    67 			'orderby'        => 'menu_order ID',
       
    68 		)
       
    69 	)
       
    70 );
       
    71 foreach ( $attachments as $k => $attachment ) :
       
    72 	if ( $attachment->ID == $post->ID ) {
       
    73 		break;
       
    74 	}
       
    75 endforeach;
       
    76 
       
    77 // If there is more than 1 attachment in a gallery
       
    78 if ( count( $attachments ) > 1 ) :
       
    79 	$k++;
       
    80 	if ( isset( $attachments[ $k ] ) ) :
       
    81 		// get the URL of the next image attachment
       
    82 		$next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
       
    83 	else :
       
    84 		// or get the URL of the first image attachment
       
    85 		$next_attachment_url = get_attachment_link( $attachments[0]->ID );
       
    86 	endif;
       
    87 else :
       
    88 	// or, if there's only 1 image, get the URL of the image
       
    89 	$next_attachment_url = wp_get_attachment_url();
       
    90 endif;
       
    91 ?>
       
    92 								<a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
       
    93 													<?php
       
    94 													/**
       
    95 													 * Filter the image attachment size to use.
       
    96 													 *
       
    97 													 * @since Twenty Twelve 1.0
       
    98 													 *
       
    99 													 * @param array $size {
       
   100 													 *     @type int The attachment height in pixels.
       
   101 													 *     @type int The attachment width in pixels.
       
   102 													 * }
       
   103 													 */
       
   104 													$attachment_size = apply_filters( 'twentytwelve_attachment_size', array( 960, 960 ) );
       
   105 													echo wp_get_attachment_image( $post->ID, $attachment_size );
       
   106 								?>
       
   107 								</a>
       
   108 
       
   109 								<?php if ( ! empty( $post->post_excerpt ) ) : ?>
       
   110 								<div class="entry-caption">
       
   111 									<?php the_excerpt(); ?>
       
   112 								</div>
       
   113 								<?php endif; ?>
       
   114 							</div><!-- .attachment -->
       
   115 
       
   116 						</div><!-- .entry-attachment -->
       
   117 
       
   118 						<div class="entry-description">
       
   119 							<?php the_content(); ?>
       
   120 							<?php
       
   121 							wp_link_pages(
       
   122 								array(
       
   123 									'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ),
       
   124 									'after'  => '</div>',
       
   125 								)
       
   126 							);
       
   127 ?>
       
   128 						</div><!-- .entry-description -->
       
   129 
       
   130 					</div><!-- .entry-content -->
       
   131 
       
   132 				</article><!-- #post -->
       
   133 
       
   134 				<?php comments_template(); ?>
       
   135 
       
   136 			<?php endwhile; // end of the loop. ?>
       
   137 
       
   138 		</div><!-- #content -->
       
   139 	</div><!-- #primary -->
       
   140 
       
   141 <?php get_footer(); ?>