Skip to content

Instantly share code, notes, and snippets.

@joshuadavidnelson
Created August 7, 2014 17:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuadavidnelson/d120bcab74d3ce8f2e30 to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/d120bcab74d3ce8f2e30 to your computer and use it in GitHub Desktop.
Modify a Soliloquy Slider's content
<?php
/**
* Modify a static image slider by adding recent posts.
*
* @author Joshua David Nelson, josh@joshuadnelson.com
*/
add_filter( 'soliloquy_output_after_container', 'jdn_soliloquy_add_custom_slides', 11, 2 );
function jdn_soliloquy_add_custom_slides( $slider, $data ) {
global $soliloquy_data;
// Bail out early if we are not targeting our specific slider. Remove this if you want it to apply to all sliders.
if ( 5037 !== $data['id'] )
return $slider;
// This is for genesis framwework, FYI - custom child theme setting for number of slides
$number = ( int ) genesis_get_option( 'slideshow_number', 'child-settings' );
if( empty( $number ) )
$number = 10;
$args = array(
'post_type' => 'post',
//'category' => 'featured', // -- Add this back in if you want a specific category to appear on the slider
'posts_per_page' => $number,
'orderby' => 'date',
'order' => 'desc',
'meta_key' => '_thumbnail_id', // only get posts with thumbnails
);
$posts = new WP_Query( $args );
if( $posts->have_posts() ):
while ( $posts->have_posts() ) : $posts->the_post();
$slide_img_url = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' );
$slider .= '<li class="soliloquy-item">';
$slider .= '<img class="soliloquy-item-image" src="' . $slide_img_url[0] . '" title="' . get_the_title() . '" alt="' . get_the_title() . '" />';
$slider .= '<div class="soliloquy-caption">';
$slider .= '<div class="soliloquy-caption-inside">';
$slider .= get_the_excerpt();
$slider .= '</div>';
$slider .= '</div>';
$slider .= '</li>';
endwhile;
endif;
// reset the query
wp_reset_postdata();
// Return the amended slider HTML with our custom slides.
return $slider;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment