Changeset 24402
- Timestamp:
- 06/03/2013 09:44:25 PM (12 years ago)
- Location:
- trunk/wp-content/themes/twentythirteen
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-content/themes/twentythirteen/functions.php
r24393 r24402 421 421 endif; 422 422 423 if ( ! function_exists( 'twentythirteen_the_attached_image' ) ) : 424 /** 425 * Prints the attached image with a link to the next attached image. 426 * 427 * @since Twenty Thirteen 1.0 428 * 429 * @return void 430 */ 431 function twentythirteen_the_attached_image() { 432 $post = get_post(); 433 $attachment_size = apply_filters( 'twentythirteen_attachment_size', array( 724, 724 ) ); 434 $next_attachment_url = wp_get_attachment_url(); 435 436 /** 437 * Grab the IDs of all the image attachments in a gallery so we can get the URL 438 * of the next adjacent image in a gallery, or the first image (if we're 439 * looking at the last image in a gallery), or, in a gallery of one, just the 440 * link to that image file. 441 */ 442 $attachments = array_values( get_children( array( 443 'post_parent' => $post->post_parent, 444 'post_status' => 'inherit', 445 'post_type' => 'attachment', 446 'post_mime_type' => 'image', 447 'order' => 'ASC', 448 'orderby' => 'menu_order ID' 449 ) ) ); 450 451 // If there is more than 1 attachment in a gallery... 452 if ( count( $attachments ) > 1 ) { 453 foreach ( $attachments as $k => $attachment ) { 454 if ( $attachment->ID == $post->ID ) 455 break; 456 } 457 $k++; 458 459 // get the URL of the next image attachment... 460 if ( isset( $attachments[ $k ] ) ) 461 $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID ); 462 463 // or get the URL of the first image attachment. 464 else 465 $next_attachment_url = get_attachment_link( $attachments[0]->ID ); 466 } 467 468 printf( '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>', 469 esc_url( $next_attachment_url ), 470 the_title_attribute( array( 'echo' => false ) ), 471 wp_get_attachment_image( $post->ID, $attachment_size ) 472 ); 473 } 474 endif; 475 423 476 /** 424 477 * Returns the URL from the post. -
trunk/wp-content/themes/twentythirteen/image.php
r23758 r24402 10 10 */ 11 11 12 the_post();13 14 /**15 * 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,16 * 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 file17 */18 $attachments = array_values( get_children( array(19 'post_parent' => $post->post_parent,20 'post_status' => 'inherit',21 'post_type' => 'attachment',22 'post_mime_type' => 'image',23 'order' => 'ASC',24 'orderby' => 'menu_order ID'25 ) ) );26 27 foreach ( $attachments as $k => $attachment ) :28 if ( $attachment->ID == $post->ID )29 break;30 endforeach;31 32 $k++;33 // If there is more than 1 attachment in a gallery34 if ( count( $attachments ) > 1 ) :35 if ( isset( $attachments[ $k ] ) ) :36 // get the URL of the next image attachment37 $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );38 else :39 // or get the URL of the first image attachment40 $next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );41 endif;42 else :43 // or, if there's only 1 image, get the URL of the image44 $next_attachment_url = wp_get_attachment_url();45 endif;46 47 12 get_header(); ?> 48 13 … … 55 20 <div class="entry-meta"> 56 21 <?php 57 $published_text 22 $published_text = __( '<span class="attachment-meta">Published on <time class="entry-date" datetime="%1$s">%2$s</time> in <a href="%3$s" title="Return to %4$s" rel="gallery">%5$s</a></span>', 'twentythirteen' ); 58 23 $post_title = get_the_title( $post->post_parent ); 59 24 if ( empty( $post_title ) || 0 == $post->post_parent ) 60 $published_text 25 $published_text = '<span class="attachment-meta"><time class="entry-date" datetime="%1$s">%2$s</time></span>'; 61 26 62 27 printf( $published_text, … … 77 42 ); 78 43 79 edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?> 44 edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); 45 ?> 80 46 </div><!-- .entry-meta --> 81 47 </header><!-- .entry-header --> … … 89 55 <div class="entry-attachment"> 90 56 <div class="attachment"> 91 <a href="<?php echo esc_url( $next_attachment_url ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment"><?php 92 $attachment_size = apply_filters( 'twentythirteen_attachment_size', array( 724, 724 ) ); 93 echo wp_get_attachment_image( $post->ID, $attachment_size ); 94 ?></a> 57 <?php twentythirteen_the_attached_image(); ?> 95 58 96 <?php if ( ! empty( $post->post_excerpt) ) : ?>59 <?php if ( has_excerpt() ) : ?> 97 60 <div class="entry-caption"> 98 61 <?php the_excerpt(); ?> … … 100 63 <?php endif; ?> 101 64 </div><!-- .attachment --> 102 103 65 </div><!-- .entry-attachment --> 104 66 … … 111 73 112 74 </div><!-- .entry-content --> 113 114 75 </article><!-- #post --> 115 76
Note: See TracChangeset
for help on using the changeset viewer.