twentythirteen_the_attached_image

Print the attached image with a link to the next attached image.

Description

twentythirteen_the_attached_image(); 

Usage

  1. if ( !function_exists( 'twentythirteen_the_attached_image' ) ) { 
  2. require_once '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = twentythirteen_the_attached_image(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/functions.php  
  1. function twentythirteen_the_attached_image() { 
  2. /** 
  3. * Filter the image attachment size to use. 
  4. * @since Twenty thirteen 1.0 
  5. * @param array $size { 
  6. * @type int The attachment height in pixels. 
  7. * @type int The attachment width in pixels. 
  8. * } 
  9. */ 
  10. $attachment_size = apply_filters( 'twentythirteen_attachment_size', array( 724, 724 ) ); 
  11. $next_attachment_url = wp_get_attachment_url(); 
  12. $post = get_post(); 
  13.  
  14. /** 
  15. * Grab the IDs of all the image attachments in a gallery so we can get the URL 
  16. * of the next adjacent image in a gallery, or the first image (if we're 
  17. * looking at the last image in a gallery), or, in a gallery of one, just the 
  18. * link to that image file. 
  19. */ 
  20. $attachment_ids = get_posts( array( 
  21. 'post_parent' => $post->post_parent,  
  22. 'fields' => 'ids',  
  23. 'numberposts' => -1,  
  24. 'post_status' => 'inherit',  
  25. 'post_type' => 'attachment',  
  26. 'post_mime_type' => 'image',  
  27. 'order' => 'ASC',  
  28. 'orderby' => 'menu_order ID',  
  29. ) ); 
  30.  
  31. // If there is more than 1 attachment in a gallery... 
  32. if ( count( $attachment_ids ) > 1 ) { 
  33. foreach ( $attachment_ids as $idx => $attachment_id ) { 
  34. if ( $attachment_id == $post->ID ) { 
  35. $next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ]; 
  36. break; 
  37.  
  38. // get the URL of the next image attachment... 
  39. if ( $next_id ) 
  40. $next_attachment_url = get_attachment_link( $next_id ); 
  41.  
  42. // or get the URL of the first image attachment. 
  43. else 
  44. $next_attachment_url = get_attachment_link( reset( $attachment_ids ) ); 
  45.  
  46. printf( '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',  
  47. esc_url( $next_attachment_url ),  
  48. the_title_attribute( array( 'echo' => false ) ),  
  49. wp_get_attachment_image( $post->ID, $attachment_size ) 
  50. );