twentyfourteen_the_attached_image

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

Description

twentyfourteen_the_attached_image(); 

Usage

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

Defined (1)

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

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