Skip to content

Instantly share code, notes, and snippets.

@RevConcept
Created January 29, 2014 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RevConcept/8695999 to your computer and use it in GitHub Desktop.
Save RevConcept/8695999 to your computer and use it in GitHub Desktop.
WordPress: Display All Post Attachment Images In A Slider. Original post here: http://revelationconcept.com/wordpress-display-all-post-attachment-images-in-a-slider
// This is modified to show the image captions
function revconcept_get_images($post_id) {
global $post;
$thumbnail_ID = get_post_thumbnail_id();
$images = get_children( array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
if ($images) :
foreach ($images as $attachment_id => $image) :
if ( $image->ID != $thumbnail_ID ) :
$img_cap = $image->post_excerpt; // New line to get the caption
$img_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); //alt
if ($img_alt == '') : $img_alt = $image->post_title; endif;
$big_array = image_downsize( $image->ID, 'large' );
$img_url = $big_array[0];
echo '<li>';
echo '<img src="';
echo $img_url;
echo '" alt="';
echo $img_alt;
echo '" />';
echo $img_cap; // New line to show the caption under the photo
echo '</li><!--end slide-->';
endif; endforeach; endif; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment