/** * Output gallery * * @since 1.0 */ function easy_image_gallery() { $attachment_ids = easy_image_gallery_get_image_ids(); global $post; if ($attachment_ids) { ?> <?php $has_gallery_images = get_post_meta(get_the_ID(), '_easy_image_gallery', true); if (!$has_gallery_images) { return; } // convert string into array $has_gallery_images = explode(',', get_post_meta(get_the_ID(), '_easy_image_gallery', true)); // clean the array (remove empty values) $has_gallery_images = array_filter($has_gallery_images); $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'feature'); $image_title = esc_attr(get_the_title(get_post_thumbnail_id($post->ID))); // css classes array $classes = array(); // thumbnail count $classes[] = $has_gallery_images ? 'thumbnails-' . easy_image_gallery_count_images() : ''; // linked images $classes[] = easy_image_gallery_has_linked_images() ? 'linked' : ''; $classes = implode(' ', $classes); ob_start(); ?> <ul class="image-gallery <?php echo $classes; ?> "> <?php foreach ($attachment_ids as $attachment_id) { $classes = array('popup'); // get original image $image_link = wp_get_attachment_image_src($attachment_id, apply_filters('easy_image_gallery_linked_image_size', 'large')); $image_link = $image_link[0]; $image = wp_get_attachment_image($attachment_id, apply_filters('easy_image_gallery_thumbnail_image_size', 'thumbnail'), '', array('alt' => trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true))))); $image_caption = get_post($attachment_id)->post_excerpt ? get_post($attachment_id)->post_excerpt : ''; $image_class = esc_attr(implode(' ', $classes)); $lightbox = easy_image_gallery_get_lightbox(); $rel = easy_image_gallery_count_images() > 1 ? 'rel="' . $lightbox . '[group]"' : 'rel="' . $lightbox . '"'; if (easy_image_gallery_has_linked_images()) { $html = sprintf('<li><a %s href="%s" class="%s" title="%s"><i class="icon-view"></i><span class="overlay"></span>%s</a></li>', $rel, $image_link, $image_class, $image_caption, $image); } else { $html = sprintf('<li>%s</li>', $image); } echo apply_filters('easy_image_gallery_html', $html, $rel, $image_link, $image_class, $image_caption, $image, $attachment_id, $post->ID); } ?> </ul> <?php $gallery = ob_get_clean(); return apply_filters('easy_image_gallery', $gallery); ?> <?php } }
/** * JS * * @since 1.0 */ function easy_image_gallery_js() { if (!easy_image_gallery_allowed_post_type() || !easy_image_gallery_is_gallery()) { return; } if (is_singular() && easy_image_gallery_has_linked_images()) { ?> <?php $lightbox = easy_image_gallery_get_lightbox(); switch ($lightbox) { case 'prettyphoto': ob_start(); ?> <script> jQuery(document).ready(function() { jQuery("a[rel^='prettyPhoto']").prettyPhoto({ social_tools : false, show_title : false }); }); </script> <?php $js = ob_get_clean(); echo apply_filters('easy_image_gallery_prettyphoto_js', $js); ?> <?php break; case 'fancybox': ob_start(); ?> <script> jQuery(document).ready(function() { jQuery("a.popup").attr('rel', 'fancybox').fancybox({ 'transitionIn' : 'elastic', 'transitionOut' : 'elastic', 'speedIn' : 200, 'speedOut' : 200, 'overlayShow' : false }); }); </script> <?php $js = ob_get_clean(); echo apply_filters('easy_image_gallery_fancybox_js', $js); ?> <?php break; default: break; } // allow developers to add/modify JS do_action('easy_image_gallery_js', $lightbox); ?> <?php } ?> <?php }