I would like to show the gallery title together with the captions. Below is my attempt, but I keep getting Notice: Trying to get property of non-object
. I still can't figure it out what went wrong.
single.php
<div class="gallery-content">
<?php
add_filter( 'shortcode_atts_gallery', 'fullsize_gallery' );
if( has_shortcode( $post->post_content, 'gallery' ) ) :
$gallery = get_post_gallery_images( $post->ID );
$image_list = '<ul class="galleryslider" style="display: none;">';
foreach( $gallery as $image ) :
$image_title = wp_get_attachment_url($image->post_title);
$image_caption = wp_get_attachment_url($image->post_excerpt);
// Loop through each image in each gallery
$image_list .= '<li><a href="'. $image . '" data-lightbox="'.$post->ID.'"><img src="' . $image . '" title="'.$image_title.'"/>'.$image_caption.'</a></li>';
endforeach;
$image_list .= '</ul>';
echo $image_list;
endif;
?>
</div><!-- .gallery-content -->
functions.php
function fullsize_gallery( $out )
{
remove_filter( current_filter(), __FUNCTION__ );
$out['size'] = 'full';
return $out;
}