catchresponsive_the_attached_image

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

Description

catchresponsive_the_attached_image(); 

Usage

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

Defined (1)

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

/inc/catchresponsive-core.php  
  1. function catchresponsive_the_attached_image() { 
  2. $post = get_post(); 
  3. $attachment_size = apply_filters( 'catchresponsive_attachment_size', array( 1200, 1200 ) ); 
  4. $next_attachment_url = wp_get_attachment_url(); 
  5.  
  6. /** 
  7. * Grab the IDs of all the image attachments in a gallery so we can get the 
  8. * URL of the next adjacent image in a gallery, or the first image (if 
  9. * we're looking at the last image in a gallery), or, in a gallery of one,  
  10. * just the link to that image file. 
  11. */ 
  12. $attachment_ids = get_posts( array( 
  13. 'post_parent' => $post->post_parent,  
  14. 'fields' => 'ids',  
  15. 'numberposts' => 1,  
  16. 'post_status' => 'inherit',  
  17. 'post_type' => 'attachment',  
  18. 'post_mime_type' => 'image',  
  19. 'order' => 'ASC',  
  20. 'orderby' => 'menu_order ID' 
  21. ) ); 
  22.  
  23. // If there is more than 1 attachment in a gallery... 
  24. if ( count( $attachment_ids ) > 1 ) { 
  25. foreach ( $attachment_ids as $attachment_id ) { 
  26. if ( $attachment_id == $post->ID ) { 
  27. $next_id = current( $attachment_ids ); 
  28. break; 
  29.  
  30. // get the URL of the next image attachment... 
  31. if ( $next_id ) 
  32. $next_attachment_url = get_attachment_link( $next_id ); 
  33.  
  34. // or get the URL of the first image attachment. 
  35. else 
  36. $next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) ); 
  37.  
  38. printf( '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',  
  39. esc_url( $next_attachment_url ),  
  40. the_title_attribute( array( 'echo' => false ) ),  
  41. wp_get_attachment_image( $post->ID, $attachment_size ) 
  42. );