Skip to content

Instantly share code, notes, and snippets.

@eri-trabiccolo
Last active August 29, 2015 14:17
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 eri-trabiccolo/712a1681ca3a32d364aa to your computer and use it in GitHub Desktop.
Save eri-trabiccolo/712a1681ca3a32d364aa to your computer and use it in GitHub Desktop.
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