I've been at this for hours so maybe someone here can help :)
Basically I have a fancybox gallery that loads images attached to a post. As you can see below, I want to echo either the image's caption or alt title into the fancybox window. Currently it works, but it only shows the alt and caption for one of the images, which looks to be the first.
I can echo the alt title and caption of each image onto the page fine, but when it's used inside the fancybox window there's an issue. Anyone know why? Do I need to do some more looping or something? thanks for looking!
<script type="text/javascript">
//<![CDATA[
var $j = jQuery.noConflict();
$j(document).ready(function() {
//fancybox
$j("a[rel=gallery]").fancybox({
'transitionIn' : 'elastic',
'transitionOut' : 'elastic',
'easingIn' : 'easeOutBack',
'easingOut' : 'easeInBack',
'speedIn' : 250,
'speedOut' : 250,
'changeSpeed' : 250,
'overlayShow' : false,
'titlePosition' : 'inside',
'titleFormat' :
function(title, currentArray, currentIndex, currentOpts) {
<?php
$images = get_children( array(
'post_parent' => $post->ID,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ID'
));
//caption
if ($images) {
foreach($images as $image) {
$caption = $image->post_excerpt;
}
}
//alt title
foreach ($images as $attachment_id => $image) {
$img_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
}
?>
//here's where I'm trying to echo the caption or alt image for testing
return '<?php echo $caption; echo $img_alt; ?><span id="fancybox-title-over"><span class="index">' + (currentIndex + 1) + ' of ' + currentArray.length + (title.length ? '</span><span class="fancybox-title">' + title : '') + '</span>' + '<span class="phone"><?php echo $phone; ?></span></span>';
}
});
});
//]]>
</script>