Wordpress 3.5
[autoinstalls/wordpress.git] / wp-content / themes / twentytwelve / image.php
1 <?php
2 /**
3  * The template for displaying image attachments.
4  *
5  * Learn more: http://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 while ( have_posts() ) : the_post(); ?>
18
19                                 <article id="post-<?php the_ID(); ?>" <?php post_class( 'image-attachment' ); ?>>
20                                         <header class="entry-header">
21                                                 <h1 class="entry-title"><?php the_title(); ?></h1>
22
23                                                 <footer class="entry-meta">
24                                                         <?php
25                                                                 $metadata = wp_get_attachment_metadata();
26                                                                 printf( __( '<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' ),
27                                                                         esc_attr( get_the_date( 'c' ) ),
28                                                                         esc_html( get_the_date() ),
29                                                                         esc_url( wp_get_attachment_url() ),
30                                                                         $metadata['width'],
31                                                                         $metadata['height'],
32                                                                         esc_url( get_permalink( $post->post_parent ) ),
33                                                                         esc_attr( strip_tags( get_the_title( $post->post_parent ) ) ),
34                                                                         get_the_title( $post->post_parent )
35                                                                 );
36                                                         ?>
37                                                         <?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
38                                                 </footer><!-- .entry-meta -->
39
40                                                 <nav id="image-navigation" class="navigation" role="navigation">
41                                                         <span class="previous-image"><?php previous_image_link( false, __( '&larr; Previous', 'twentytwelve' ) ); ?></span>
42                                                         <span class="next-image"><?php next_image_link( false, __( 'Next &rarr;', 'twentytwelve' ) ); ?></span>
43                                                 </nav><!-- #image-navigation -->
44                                         </header><!-- .entry-header -->
45
46                                         <div class="entry-content">
47
48                                                 <div class="entry-attachment">
49                                                         <div class="attachment">
50 <?php
51 /**
52  * 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,
53  * 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
54  */
55 $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' ) ) );
56 foreach ( $attachments as $k => $attachment ) :
57         if ( $attachment->ID == $post->ID )
58                 break;
59 endforeach;
60
61 $k++;
62 // If there is more than 1 attachment in a gallery
63 if ( count( $attachments ) > 1 ) :
64         if ( isset( $attachments[ $k ] ) ) :
65                 // get the URL of the next image attachment
66                 $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
67         else :
68                 // or get the URL of the first image attachment
69                 $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
70         endif;
71 else :
72         // or, if there's only 1 image, get the URL of the image
73         $next_attachment_url = wp_get_attachment_url();
74 endif;
75 ?>
76                                                                 <a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php
77                                                                 $attachment_size = apply_filters( 'twentytwelve_attachment_size', array( 960, 960 ) );
78                                                                 echo wp_get_attachment_image( $post->ID, $attachment_size );
79                                                                 ?></a>
80
81                                                                 <?php if ( ! empty( $post->post_excerpt ) ) : ?>
82                                                                 <div class="entry-caption">
83                                                                         <?php the_excerpt(); ?>
84                                                                 </div>
85                                                                 <?php endif; ?>
86                                                         </div><!-- .attachment -->
87
88                                                 </div><!-- .entry-attachment -->
89
90                                                 <div class="entry-description">
91                                                         <?php the_content(); ?>
92                                                         <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
93                                                 </div><!-- .entry-description -->
94
95                                         </div><!-- .entry-content -->
96
97                                 </article><!-- #post -->
98
99                                 <?php comments_template(); ?>
100
101                         <?php endwhile; // end of the loop. ?>
102
103                 </div><!-- #content -->
104         </div><!-- #primary -->
105
106 <?php get_footer(); ?>