Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('tc_core', 'use_custom_slider_class');
- function use_custom_slider_class($classes){
- //don't instanciate default class
- unset( $classes['content'][
- array_search(array('inc/parts','slider'), $classes['content'])
- ]
- );
- //instanciate our class
- new TC_Slider_mod;
- return $classes;
- }
- add_filter('tc_slider_name_id', 'my_slider_of_posts');
- function my_slider_of_posts( $slider_name_id ){
- if ( $slider_name_id == 'front-slider' )
- return array(
- 'slider' => 'front-slider',
- 'query' => array(
- 'tag' => "front-slider",
- 'posts_per_page' => 5,
- 'order' => 'desc'
- )
- );
- return $slider_name_id;
- }
- define('CUSTOMIZR', get_template_directory() );
- require_once( CUSTOMIZR . '/inc/parts/class-content-slider.php');
- class TC_Slider_mod extends TC_slider{
- // override tc_get_slides
- function tc_get_slides($slider_name_id, $img_size){
- if ( ! is_array($slider_name_id) )
- return parent::tc_get_slides($slider_name_id, $img_size);
- // from here starts a slightly different version of the parent::tc_get_slides
- extract($slider_name_id);
- $all_sliders = tc__f('__get_option' , 'tc_sliders');
- $saved_slides = ( isset($all_sliders[$slider]) ) ? $all_sliders[$slider] : false;
- //if the slider not longer exists or exists but is empty, return false
- if ( !isset($saved_slides) || !is_array($saved_slides) || empty($saved_slides) )
- return;
- $posts = new WP_Query($query);
- // if you don't want to show the first attachment when featured image isn't set
- // remove the line below
- add_filter('tc_show_single_post_content', '__return_false');
- // build our array of slides
- //inititalize the slides array
- $slides = array();
- //init slide active state index
- $i = 0;
- while ( $posts -> have_posts() ){
- $posts -> the_post();
- //title
- $title = get_the_title();
- $default_title_length = apply_filters( 'tc_slide_title_length', 80 );
- $title = ( strlen($title) > $default_title_length ) ? substr( $title,0,strpos( $title, ' ' , $default_title_length) ). ' ...' : $title;
- //lead text
- $text = get_the_excerpt();
- $default_text_length = apply_filters( 'tc_slide_text_length', 250 );
- $text = ( strlen($text) > $default_text_length ) ? substr( $text,0,strpos( $text, ' ' ,$default_text_length) ). ' ...' : $text;
- //button text
- $button_text = __('Read more »', 'customizr');
- $default_button_length = apply_filters( 'tc_slide_button_length', 80 );
- $button_text = ( strlen($button_text) > $default_button_length ) ? substr( $button_text,0,strpos( $button_text, ' ' ,$default_button_length)). ' ...' : $button_text;
- //link post id
- $link_id = get_the_id();
- $id = $link_id;
- //button link
- $link_url = $link_id ? get_permalink( $link_id ) : 'javascript:void(0)';
- //sets the first slide active
- $active = ( 0 == $i ) ? 'active' : '';
- $color_style = '';
- //attachment image
- $alt = apply_filters( 'tc_slide_background_alt' , trim(strip_tags( get_the_title() ) ) );
- $slide_background = TC_post_thumbnails::$instance->tc_get_thumbnail_data($img_size)[0];
- //adds all values to the slide array only if the content exists (=> handle the case when an attachment has been deleted for example). Otherwise apply a default slide
- if ( empty($slide_background) )
- $slide_background = wp_get_attachment_image( $saved_slides[1], $img_size, false, array( 'class' => 'slide' , 'alt' => $alt ) );
- $slides[$id] = array(
- 'title' => $title,
- 'text' => $text,
- 'button_text' => $button_text,
- 'link_id' => $link_id,
- 'link_url' => $link_url,
- 'active' => $active,
- 'color_style' => $color_style,
- 'slide_background' => $slide_background,
- );
- //increments active index
- $i++;
- }//end of slides loop
- // if you chose to not show the first attachment when featured image isn't set
- // remove the line below
- remove_filter('tc_show_single_post_content', '__return_false');
- wp_reset_postdata();
- //returns the slides or false if nothing
- return ( !empty($slides) ) ? $slides : false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement