Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add slides to the slider of recent posts
add_filter('tc_post_slides', 'add_custom_slides', 10, 2);
function add_custom_slides( $slides, $img_size){
$slides = is_array( $slides ) ? $slides : array();
/*
* set this as an empty array if you don't want slides before this way:
* $my_slides_before = array();
*/
$my_slides_before = array(
'my_316' => array( // replace my_316 with my_ID_of_your_attachment
'title' => 'Some title',
'text' => 'Some text',
'button_text' => 'button text',
'link_id' => 'some link',
'link_url' => 'some url',
'active' => 'active',
'color_style' => '',
'slide_background' => wp_get_attachment_image( 316, $img_size, false, array( 'class' => 'slide', 'alt' => 'First Slide') ), /* Replace 316 with the id of your desired attachment and the alt 'First Slide' */
),
'my_317' => array( // replace my_317 with my_ID_of_your_attachment
'title' => 'Some title',
'text' => 'Some text',
'button_text' => 'button text',
'link_id' => 'some link',
'link_url' => 'some url',
'active' => '',
'color_style' => '',
'slide_background' => wp_get_attachment_image( 317, $img_size, false, array( 'class' => 'slide', 'alt' => 'Second Slide') ), /* Replace 317 with the id of your desired attachment */
)
);
// same thing with slides after:
/*
* set this as an empty array if you don't want slides after this way:
* $my_slides_after = array();
*/
$my_slides_after = array(
'my_318' => array( // replace my_318 with my_ID_of_your_attachment
'title' => 'Some title',
'text' => 'Some text',
'button_text' => 'button text',
'link_id' => 'some link',
'link_url' => 'some url',
'active' => '',
'color_style' => '',
'slide_background' => wp_get_attachment_image( 318, $img_size, false, array( 'class' => 'slide', 'alt' => 'Last -1 Slide') ), /* Replace 318 with the id of your desired attachment */
),
'my_319' => array( // replace my_319 with my_ID_of_your_attachment
'title' => 'Some title',
'text' => 'Some text',
'button_text' => 'button text',
'link_id' => 'some link',
'link_url' => 'some url',
'active' => '',
'color_style' => '',
'slide_background' => wp_get_attachment_image( 319, $img_size, false, array( 'class' => 'slide', 'alt' => 'Last Slide') ), /* Replace 319 with the id of your desired attachment */
)
);
/* reset the active post slide if we have to add slides before */
if ( ! empty( $my_slides_before ) && $slides ) {
$keys = array_keys($slides);
$first_slide_key = $keys[0];
$slides[ $first_slide_key ]['active'] = false; //reset active
}
$slides = array_merge($my_slides_before, $slides, $my_slides_after);
return $slides;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment