Created
September 26, 2013 00:45
-
-
Save bMinaise/6708327 to your computer and use it in GitHub Desktop.
Get Gallery Image URLs
Sample plugin illustrating how to retrieve all image URLs of gallery images in a post
Author: Pippin Williamson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pw_show_gallery_image_urls( $content ) { | |
global $post; | |
// Only do this on singular items | |
if( ! is_singular() ) | |
return $content; | |
// Make sure the post has a gallery in it | |
if( ! has_shortcode( $post->post_content, 'gallery' ) ) | |
return $content; | |
// Retrieve all galleries of this post | |
$galleries = get_post_galleries_images( $post ); | |
$image_list = '<div id="carousel" class="carousel slide"><div class="carousel-inner">'; | |
// Loop through all galleries found | |
foreach( $galleries as $gallery ) { | |
// Loop through each image in each gallery | |
foreach( $gallery as $image ) { | |
$image_list .= '<div class="item"><img src=' . $image . ' /></div>'; | |
} | |
} | |
$image_list .= '</div></div>'; | |
// Append our image list to the content of our post | |
$content .= $image_list; | |
return $content; | |
} | |
add_filter( 'the_content', 'pw_show_gallery_image_urls' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment