Created
March 21, 2013 17:49
-
-
Save thomasgriffin/5215083 to your computer and use it in GitHub Desktop.
Create a slider from current gallery images of each post in the featured content slider.
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
<?php | |
add_filter( 'tgmsp_slider_images', 'tgm_custom_gallery_images', 100, 2 ); | |
function tgm_custom_gallery_images( $images, $meta ) { | |
// If the Featured Content Addon is not active, return early. | |
if ( ! class_exists( 'Tgmsp_FC' ) ) | |
return $images; | |
// Go ahead and get image attachment size. | |
if ( isset( $meta['custom'] ) && $meta['custom'] ) | |
$size = $meta['custom']; | |
else | |
$size = 'full'; | |
// Re-apply the query args from the featured slider. | |
$pid = wp_get_post_parent_id( $images[0]['id'] ); | |
$posts = get_posts( Tgmsp_FC_Shortcode::get_instance()->query_args( array(), $pid ) ); | |
if ( $posts ) : | |
$current_gallery_images = array(); | |
foreach ( (array) $posts as $post ) : | |
$attachments = get_posts( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'DESC' ) ); | |
if ( $attachments ) : | |
foreach( (array) $attachments as $attachment ) : | |
$image = wp_get_attachment_image_src( $attachment->ID, $size ); | |
$data = apply_filters( 'tgmsp_image_data', array( | |
'id' => $attachment->ID, | |
'src' => $image[0], | |
'width' => $image[1], | |
'height' => $image[2], | |
'title' => isset( $attachment->post_title ) ? $attachment->post_title : '', | |
'caption' => isset( $attachment->post_excerpt ) ? $attachment->post_excerpt : '' | |
), $attachment, $post->ID ); | |
$current_gallery_images[] = Tgmsp_FC_Shortcode::get_instance()->featured_image_data( $data, $attachment, $pid ); | |
endforeach; | |
endif; | |
endforeach; | |
endif; | |
return $current_gallery_images; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment