Changeset 43571 for trunk/src/wp-content/themes/twentyeleven/image.php
- Timestamp:
- 08/17/2018 01:50:26 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentyeleven/image.php
r42343 r43571 52 52 <div class="entry-attachment"> 53 53 <div class="attachment"> 54 <?php55 /*56 57 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 }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 } 76 76 77 // If there is more than 1 attachment in a gallery78 if ( count( $attachments ) > 1 ) {79 $k++;80 if ( isset( $attachments[ $k ] ) ) {81 // get the URL of the next image attachment82 $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );83 } else { // or get the URL of the first image attachment84 $next_attachment_url = get_attachment_link( $attachments[0]->ID );85 }86 } else {87 // or, if there's only 1 image, get the URL of the image88 $next_attachment_url = wp_get_attachment_url();89 }90 ?>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 { // or get the URL of the first image attachment 84 $next_attachment_url = get_attachment_link( $attachments[0]->ID ); 85 } 86 } else { 87 // or, if there's only 1 image, get the URL of the image 88 $next_attachment_url = wp_get_attachment_url(); 89 } 90 ?> 91 91 <a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"> 92 92 <?php … … 100 100 $attachment_size = apply_filters( 'twentyeleven_attachment_size', 848 ); 101 101 echo wp_get_attachment_image( $post->ID, array( $attachment_size, 1024 ) ); // filterable image width with 1024px limit for image height. 102 ?>102 ?> 103 103 </a> 104 104 … … 121 121 ) 122 122 ); 123 ?>123 ?> 124 124 </div><!-- .entry-description --> 125 125
Note: See TracChangeset
for help on using the changeset viewer.