Skip to content

Instantly share code, notes, and snippets.

@thomasgriffin
Created March 21, 2013 17:49
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 thomasgriffin/5215083 to your computer and use it in GitHub Desktop.
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.
<?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