[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * The template for displaying image attachments 4 * 5 * @link https://developer.wordpress.org/themes/basics/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 /* translators: 1: Date, 2: Date, 3: Attachment URL, 4: Image width in pixels, 5: Image height in pixels, 6: Post parent permalink, 7: Post parent title, 8: Post parent title. */ 31 __( '<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 × %5$s</a> in <a href="%6$s" title="Go to %7$s" rel="gallery">%8$s</a>.', 'twentytwelve' ), 32 esc_attr( get_the_date( 'c' ) ), 33 esc_html( get_the_date() ), 34 esc_url( wp_get_attachment_url() ), 35 $metadata['width'], 36 $metadata['height'], 37 esc_url( get_permalink( $post->post_parent ) ), 38 esc_attr( strip_tags( get_the_title( $post->post_parent ) ) ), 39 get_the_title( $post->post_parent ) 40 ); 41 ?> 42 <?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?> 43 </footer><!-- .entry-meta --> 44 45 <nav id="image-navigation" class="navigation"> 46 <span class="previous-image"><?php previous_image_link( false, __( '← Previous', 'twentytwelve' ) ); ?></span> 47 <span class="next-image"><?php next_image_link( false, __( 'Next →', 'twentytwelve' ) ); ?></span> 48 </nav><!-- #image-navigation --> 49 </header><!-- .entry-header --> 50 51 <div class="entry-content"> 52 53 <div class="entry-attachment"> 54 <div class="attachment"> 55 <?php 56 /* 57 * 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, 58 * 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 59 */ 60 $attachments = array_values( 61 get_children( 62 array( 63 'post_parent' => $post->post_parent, 64 'post_status' => 'inherit', 65 'post_type' => 'attachment', 66 'post_mime_type' => 'image', 67 'order' => 'ASC', 68 'orderby' => 'menu_order ID', 69 ) 70 ) 71 ); 72 foreach ( $attachments as $k => $attachment ) : 73 if ( $attachment->ID == $post->ID ) { 74 break; 75 } 76 endforeach; 77 78 // If there is more than 1 attachment in a gallery... 79 if ( count( $attachments ) > 1 ) : 80 $k++; 81 if ( isset( $attachments[ $k ] ) ) : 82 // ...get the URL of the next image attachment. 83 $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID ); 84 else : 85 // ...or get the URL of the first image attachment. 86 $next_attachment_url = get_attachment_link( $attachments[0]->ID ); 87 endif; 88 else : 89 // Or, if there's only 1 image, get the URL of the image. 90 $next_attachment_url = wp_get_attachment_url(); 91 endif; 92 ?> 93 <a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"> 94 <?php 95 /** 96 * Filters the image attachment size to use. 97 * 98 * @since Twenty Twelve 1.0 99 * 100 * @param array $size { 101 * @type int The attachment height in pixels. 102 * @type int The attachment width in pixels. 103 * } 104 */ 105 $attachment_size = apply_filters( 'twentytwelve_attachment_size', array( 960, 960 ) ); 106 echo wp_get_attachment_image( $post->ID, $attachment_size ); 107 ?> 108 </a> 109 110 <?php if ( ! empty( $post->post_excerpt ) ) : ?> 111 <div class="entry-caption"> 112 <?php the_excerpt(); ?> 113 </div> 114 <?php endif; ?> 115 </div><!-- .attachment --> 116 117 </div><!-- .entry-attachment --> 118 119 <div class="entry-description"> 120 <?php the_content(); ?> 121 <?php 122 wp_link_pages( 123 array( 124 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 125 'after' => '</div>', 126 ) 127 ); 128 ?> 129 </div><!-- .entry-description --> 130 131 </div><!-- .entry-content --> 132 133 </article><!-- #post --> 134 135 <?php comments_template(); ?> 136 137 <?php endwhile; // End of the loop. ?> 138 139 </div><!-- #content --> 140 </div><!-- #primary --> 141 142 <?php get_footer(); ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:03 2024 | Cross-referenced by PHPXref 0.7.1 |