Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. add_filter('tc_core', 'use_custom_slider_class');
  2. function use_custom_slider_class($classes){
  3. //don't instanciate default class
  4. unset( $classes['content'][
  5. array_search(array('inc/parts','slider'), $classes['content'])
  6. ]
  7. );
  8. //instanciate our class
  9. new TC_Slider_mod;
  10. return $classes;
  11. }
  12. add_filter('tc_slider_name_id', 'my_slider_of_posts');
  13. function my_slider_of_posts( $slider_name_id ){
  14. if ( $slider_name_id == 'front-slider' )
  15. return array(
  16. 'slider' => 'front-slider',
  17. 'query' => array(
  18. 'tag' => "front-slider",
  19. 'posts_per_page' => 5,
  20. 'order' => 'desc'
  21. )
  22. );
  23. return $slider_name_id;
  24. }
  25. define('CUSTOMIZR', get_template_directory() );
  26. require_once( CUSTOMIZR . '/inc/parts/class-content-slider.php');
  27. class TC_Slider_mod extends TC_slider{
  28.  
  29. // override tc_get_slides
  30. function tc_get_slides($slider_name_id, $img_size){
  31. if ( ! is_array($slider_name_id) )
  32. return parent::tc_get_slides($slider_name_id, $img_size);
  33.  
  34. // from here starts a slightly different version of the parent::tc_get_slides
  35. extract($slider_name_id);
  36.  
  37. $all_sliders = tc__f('__get_option' , 'tc_sliders');
  38. $saved_slides = ( isset($all_sliders[$slider]) ) ? $all_sliders[$slider] : false;
  39. //if the slider not longer exists or exists but is empty, return false
  40. if ( !isset($saved_slides) || !is_array($saved_slides) || empty($saved_slides) )
  41. return;
  42.  
  43. $posts = new WP_Query($query);
  44.  
  45. // if you don't want to show the first attachment when featured image isn't set
  46. // remove the line below
  47. add_filter('tc_show_single_post_content', '__return_false');
  48.  
  49. // build our array of slides
  50.  
  51. //inititalize the slides array
  52. $slides = array();
  53.  
  54. //init slide active state index
  55. $i = 0;
  56. while ( $posts -> have_posts() ){
  57. $posts -> the_post();
  58.  
  59. //title
  60. $title = get_the_title();
  61. $default_title_length = apply_filters( 'tc_slide_title_length', 80 );
  62. $title = ( strlen($title) > $default_title_length ) ? substr( $title,0,strpos( $title, ' ' , $default_title_length) ). ' ...' : $title;
  63. //lead text
  64. $text = get_the_excerpt();
  65. $default_text_length = apply_filters( 'tc_slide_text_length', 250 );
  66. $text = ( strlen($text) > $default_text_length ) ? substr( $text,0,strpos( $text, ' ' ,$default_text_length) ). ' ...' : $text;
  67.  
  68. //button text
  69. $button_text = __('Read more »', 'customizr');
  70. $default_button_length = apply_filters( 'tc_slide_button_length', 80 );
  71. $button_text = ( strlen($button_text) > $default_button_length ) ? substr( $button_text,0,strpos( $button_text, ' ' ,$default_button_length)). ' ...' : $button_text;
  72.  
  73. //link post id
  74. $link_id = get_the_id();
  75.  
  76. $id = $link_id;
  77. //button link
  78. $link_url = $link_id ? get_permalink( $link_id ) : 'javascript:void(0)';
  79.  
  80. //sets the first slide active
  81. $active = ( 0 == $i ) ? 'active' : '';
  82.  
  83. $color_style = '';
  84.  
  85. //attachment image
  86. $alt = apply_filters( 'tc_slide_background_alt' , trim(strip_tags( get_the_title() ) ) );
  87. $slide_background = TC_post_thumbnails::$instance->tc_get_thumbnail_data($img_size)[0];
  88. //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
  89. if ( empty($slide_background) )
  90. $slide_background = wp_get_attachment_image( $saved_slides[1], $img_size, false, array( 'class' => 'slide' , 'alt' => $alt ) );
  91.  
  92. $slides[$id] = array(
  93. 'title' => $title,
  94. 'text' => $text,
  95. 'button_text' => $button_text,
  96. 'link_id' => $link_id,
  97. 'link_url' => $link_url,
  98. 'active' => $active,
  99. 'color_style' => $color_style,
  100. 'slide_background' => $slide_background,
  101. );
  102.  
  103. //increments active index
  104. $i++;
  105. }//end of slides loop
  106.  
  107. // if you chose to not show the first attachment when featured image isn't set
  108. // remove the line below
  109. remove_filter('tc_show_single_post_content', '__return_false');
  110.  
  111. wp_reset_postdata();
  112.  
  113. //returns the slides or false if nothing
  114. return ( !empty($slides) ) ? $slides : false;
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement