twentyeleven_get_gallery_images

Retrieve the IDs for images in a gallery.

Description

(array) twentyeleven_get_gallery_images(); 

Returns (array)

List of image IDs from the post gallery.


Usage

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

Defined (1)

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

/functions.php  
  1. function twentyeleven_get_gallery_images() { 
  2. $images = array(); 
  3.  
  4. if ( function_exists( 'get_post_galleries' ) ) { 
  5. $galleries = get_post_galleries( get_the_ID(), false ); 
  6. if ( isset( $galleries[0]['ids'] ) ) 
  7. $images = explode( ', ', $galleries[0]['ids'] ); 
  8. } else { 
  9. $pattern = get_shortcode_regex(); 
  10. preg_match( "/$pattern/s", get_the_content(), $match ); 
  11. $atts = shortcode_parse_atts( $match[3] ); 
  12. if ( isset( $atts['ids'] ) ) 
  13. $images = explode( ', ', $atts['ids'] ); 
  14.  
  15. if ( ! $images ) { 
  16. $images = get_posts( array( 
  17. 'fields' => 'ids',  
  18. 'numberposts' => 999,  
  19. 'order' => 'ASC',  
  20. 'orderby' => 'menu_order',  
  21. 'post_mime_type' => 'image',  
  22. 'post_parent' => get_the_ID(),  
  23. 'post_type' => 'attachment',  
  24. ) ); 
  25.  
  26. return $images;