Guest User

featured-slider.php

a guest
Oct 20th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.48 KB | None | 0 0
  1. <?php
  2. /**
  3. * The template for displaying the Slider
  4. *
  5. * @package Catch_Fullscreen
  6. */
  7.  
  8. if ( ! function_exists( 'catch_fullscreen_featured_slider' ) ) :
  9. /**
  10. * Add slider.
  11. *
  12. * @uses action hook catch_fullscreen_before_content.
  13. *
  14. * @since Catch Fullscreen Pro 1.0
  15. */
  16. function catch_fullscreen_featured_slider() {
  17. $enable_slider = get_theme_mod( 'catch_fullscreen_slider_option', 'disabled' );
  18.  
  19. if ( catch_fullscreen_check_section( $enable_slider ) ) {
  20. $type = get_theme_mod( 'catch_fullscreen_slider_type', 'category' );
  21. $transition_effect = get_theme_mod( 'catch_fullscreen_slider_transition_effect', 'fade' );
  22. $transition_length = get_theme_mod( 'catch_fullscreen_slider_transition_length', 1 );
  23. $transition_delay = get_theme_mod( 'catch_fullscreen_slider_transition_delay', 4 );
  24. $image_loader = get_theme_mod( 'catch_fullscreen_slider_image_loader', false );
  25. $pause_on_hover = get_theme_mod( 'catch_fullscreen_pause_on_hover', 1 );
  26.  
  27. if( $pause_on_hover ) {
  28. $value = 'true';
  29. } else {
  30. $value = 'false';
  31. }
  32.  
  33. $anchor = get_theme_mod( 'catch_fullscreen_slider_anchor', 'featured-slider-section' );
  34.  
  35. $output = '
  36. <div id="feature-slider-section" data-anchor="' . esc_attr( $anchor ) . '" class="section">
  37. <div class="wrapper">
  38. <div class="cycle-slideshow"
  39. data-cycle-log="false"
  40. data-cycle-pause-on-hover="' . esc_attr( $value ) . '"
  41. data-cycle-swipe="true"
  42. data-cycle-auto-height=container
  43. data-cycle-fx="' . esc_attr( $transition_effect ) . '"
  44. data-cycle-speed="' . esc_attr( $transition_length * 1000 ) . '"
  45. data-cycle-timeout="' . esc_attr( $transition_delay * 1000 ) . '"
  46. data-cycle-loader="' . esc_attr( $image_loader ) . '"
  47. data-cycle-slides="> article"
  48. >
  49.  
  50. <!-- prev/next links -->
  51. <button class="cycle-prev" aria-label="Previous"><span class="screen-reader-text">' . esc_html__( 'Previous Slide', 'catch-fullscreen-pro' ) . '</span>' . catch_fullscreen_get_svg( array( 'icon' => 'angle-down' ) ) . '</button>
  52. <button class="cycle-next" aria-label="Next"><span class="screen-reader-text">' . esc_html__( 'Next Slide', 'catch-fullscreen-pro' ) . '</span>' . catch_fullscreen_get_svg( array( 'icon' => 'angle-down' ) ) . '</button>
  53.  
  54.  
  55. <!-- empty element for pager links -->
  56. <div class="cycle-pager"></div>';
  57. // Select Slider
  58. if ( 'post' === $type || 'page' === $type || 'category' === $type ) {
  59. $output .= catch_fullscreen_post_page_category_slider();
  60. } elseif ( 'image' === $type ) {
  61. $output .= catch_fullscreen_image_slider();
  62. }
  63.  
  64. $output .= '
  65. </div><!-- .cycle-slideshow -->
  66. </div><!-- .wrapper -->
  67. </div><!-- #feature-slider -->';
  68.  
  69. echo $output;
  70. } // End if().
  71. }
  72. endif;
  73. add_action( 'catch_fullscreen_slider', 'catch_fullscreen_featured_slider', 10 );
  74.  
  75.  
  76. if ( ! function_exists( 'catch_fullscreen_post_page_category_slider' ) ) :
  77. /**
  78. * This function to display featured posts/page/category slider
  79. *
  80. * @param $options: catch_fullscreen_theme_options from customizer
  81. *
  82. * @since Catch Fullscreen Pro 1.0
  83. */
  84. function catch_fullscreen_post_page_category_slider() {
  85. $quantity = get_theme_mod( 'catch_fullscreen_slider_number', 4 );
  86. $no_of_post = 0; // for number of posts
  87. $post_list = array();// list of valid post/page ids
  88. $type = get_theme_mod( 'catch_fullscreen_slider_type', 'category' );
  89. $show_content = get_theme_mod( 'catch_fullscreen_slider_content_show', 'hide-content' );
  90. $show_meta = get_theme_mod( 'catch_fullscreen_slider_meta_show', 'show-meta' );
  91. $output = '';
  92.  
  93. $args = array(
  94. 'ignore_sticky_posts' => 1, // ignore sticky posts
  95. 'orderby' => 'rand',
  96. );
  97.  
  98. //Get valid number of posts
  99. if ( 'post' === $type || 'page' === $type ) {
  100. for ( $i = 1; $i <= $quantity; $i++ ) {
  101. $post_id = '';
  102.  
  103. if ( 'post' === $type ) {
  104. $post_id = get_theme_mod( 'catch_fullscreen_slider_post_' . $i );
  105. } elseif ( 'page' === $type ) {
  106. $post_id = get_theme_mod( 'catch_fullscreen_slider_page_' . $i );
  107.  
  108. $args['post_type'] = 'page';
  109. }
  110.  
  111. if ( $post_id && '' !== $post_id ) {
  112. $post_list = array_merge( $post_list, array( $post_id ) );
  113.  
  114. $no_of_post++;
  115. }
  116. }
  117.  
  118. $args['post__in'] = $post_list;
  119. $args['orderby'] = 'post__in';
  120. } elseif ( 'category' === $type ) {
  121. $no_of_post = $quantity;
  122.  
  123. $args['category__in'] = get_theme_mod( 'catch_fullscreen_slider_select_category' );
  124.  
  125. $args['post_type'] = 'post';
  126. }
  127.  
  128. if ( ! $no_of_post ) {
  129. return;
  130. }
  131.  
  132. $args['posts_per_page'] = $no_of_post;
  133.  
  134. $loop = new WP_Query( $args );
  135.  
  136. while ( $loop->have_posts() ) :
  137. $loop->the_post();
  138.  
  139. $title_attribute = the_title_attribute( 'echo=0' );
  140.  
  141. $content_alignment = get_theme_mod( 'catch_fullscreen_content_align_' . ( $loop->current_post + 1 ), 'content-align-center' );
  142.  
  143. if ( 0 === $loop->current_post ) {
  144. $classes = 'post post-' . get_the_ID() . ' hentry slides displayblock ' . $content_alignment;
  145. } else {
  146. $classes = 'post post-' . get_the_ID() . ' hentry slides displaynone ' . $content_alignment;
  147. }
  148.  
  149. // Default value if there is no featurd image or first image.
  150. $image_url = trailingslashit( esc_url ( get_template_directory_uri() ) ) . 'assets/images/no-thumb-1920x1080.jpg';
  151.  
  152. if ( has_post_thumbnail() ) {
  153. $image_url = get_the_post_thumbnail_url( get_the_ID(), 'catch-fullscreen-slider' );
  154. } else {
  155. // Get the first image in page, returns false if there is no image.
  156. $first_image_url = catch_fullscreen_get_first_image( get_the_ID(), 'catch-fullscreen-slider', '', true );
  157.  
  158. // Set value of image as first image if there is an image present in the page.
  159. if ( $first_image_url ) {
  160. $image_url = $first_image_url;
  161. }
  162. }
  163.  
  164. $style ='';
  165.  
  166. if ( $image_url ) {
  167. $style = ' style="background-image: url(' . esc_url( $image_url ) . ')"';
  168. }
  169.  
  170.  
  171. $output .= '
  172. <article class="content-background ' . esc_attr( $classes ) . '"' . $style . '><div class="post-wrapper">';
  173. $output .= '
  174. <div class="slider-image-wrapper">
  175. <a href="' . esc_url( get_permalink() ) . '" title="' . $title_attribute . '">
  176. <img src="' . esc_url( $image_url ) . '" class="wp-post-image" alt="' . $title_attribute . '">
  177. </a>
  178. </div><!-- .slider-image-wrapper -->
  179.  
  180. <div class="slider-content-wrapper entry-content-wrapper">
  181. <div class="entry-container">
  182. <header class="entry-header">';
  183. $output .= '<h2 class="entry-title">
  184. <a title="' . $title_attribute . '" href="' . esc_url( get_permalink() ) . '">' . the_title( '<span>','</span>', false ) . '</a>
  185. </h2>';
  186.  
  187. if ( 'show-meta' === $show_meta && ( 'post' === $type || 'category' === $type ) ) {
  188. $output .= catch_fullscreen_entry_category_date();
  189. }
  190.  
  191. $output .= '
  192. </header>
  193. ';
  194.  
  195. if ( 'excerpt' === $show_content ) {
  196. $excerpt = get_the_excerpt();
  197.  
  198. $output .= '<div class="entry-summary"><p>' . $excerpt . '</p></div><!-- .entry-summary -->';
  199. } elseif ( 'full-content' === $show_content ) {
  200. $content = apply_filters( 'the_content', get_the_content() );
  201. $content = str_replace( ']]>', ']]&gt;', $content );
  202. $output .= '<div class="entry-content">' . wp_kses_post( $content ) . '</div><!-- .entry-content -->';
  203. }
  204.  
  205. $output .= '
  206. </div><!-- .entry-container -->
  207. </div><!-- .slider-content-wrapper -->
  208. </div></article><!-- .slides -->';
  209. endwhile;
  210.  
  211. wp_reset_postdata();
  212.  
  213. return $output;
  214. }
  215. endif; // catch_fullscreen_post_page_category_slider.
  216.  
  217.  
  218. if ( ! function_exists( 'catch_fullscreen_image_slider' ) ) :
  219. /**
  220. * This function to display featured posts slider
  221. *
  222. * @get the data value from theme options
  223. * @displays on the index
  224. *
  225. * @usage Featured Image, Title and Excerpt of Post
  226. *
  227. */
  228. function catch_fullscreen_image_slider() {
  229. $quantity = get_theme_mod( 'catch_fullscreen_slider_number', 4 );
  230.  
  231. $output = '';
  232.  
  233. for ( $i = 1; $i <= $quantity; $i++ ) {
  234. $image = get_theme_mod( 'catch_fullscreen_slider_image_' . $i );
  235. $content_alignment = get_theme_mod( 'catch_fullscreen_content_align_' . $i, 'content-align-center' );
  236.  
  237. // Check Image Not Empty to add in the slides.
  238. if ( $image ) {
  239. $imagetitle = get_theme_mod( 'catch_fullscreen_featured_title_' . $i ) ? get_theme_mod( 'catch_fullscreen_featured_title_' . $i ) : 'Featured Image-' . $i;
  240.  
  241. $title = '';
  242. $link = get_theme_mod( 'catch_fullscreen_featured_link_' . $i );
  243. $target = get_theme_mod( 'catch_fullscreen_featured_target_' . $i ) ? '_blank' : '_self';
  244.  
  245. $title = '<header class="entry-header"><h2 class="entry-title"><span>' . esc_html( $imagetitle ) . '</span></h2></header>';
  246.  
  247. if ( $link ) {
  248. $title = '<header class="entry-header"><h2 class="entry-title"><a title="' . esc_attr( $imagetitle ) . '" href="' . esc_url( $link ) . '" target="' . $target . '"><span>' . esc_html( $imagetitle ) . '</span></a></h2></header>';
  249. }
  250.  
  251. $content = get_theme_mod( 'catch_fullscreen_featured_content_' . $i ) ? '<div class="entry-summary"><p>' . get_theme_mod( 'catch_fullscreen_featured_content_' . $i ) . '</p></div><!-- .entry-summary -->' : '';
  252.  
  253. $contentopening = '';
  254. $contentclosing = '';
  255.  
  256. // Content Opening and Closing.
  257. if ( ! empty( $title ) || ! empty( $content ) ) {
  258. $contentopening = '<div class="slider-content-wrapper"><div class="entry-container">';
  259. $contentclosing = '</div><!-- .entry-container --></div><!-- .slider-content-wrapper -->';
  260. }
  261.  
  262. // Adding in Classes for Display block and none.
  263. if ( 1 === $i ) {
  264. $classes = 'displayblock';
  265. } else {
  266. $classes = 'displaynone';
  267. }
  268.  
  269. $classes .= 'image-slides hentry slider-image images-' . $i . ' slides ' . $content_alignment;
  270.  
  271. $output .= '
  272. <article class="' . esc_attr( $classes ) . '" style="background-image: url(' . esc_url( $image ) . ')">
  273. <div class="slider-image-wrapper">
  274. <a href="' . esc_url( $link ) . '" title="' . esc_attr( $imagetitle ) . '">
  275. <img src="' . esc_url( $image ) . '" class="wp-post-image" alt="' . esc_attr( $imagetitle ) . '">
  276. </a>
  277. </div>
  278. ' . $contentopening . $title . $content . $contentclosing . '
  279. </article><!-- .slides --> ';
  280. } // End if().
  281. } // End for().
  282. return $output;
  283. }
  284. endif; // catch_fullscreen_image_slider.
  285.  
Add Comment
Please, Sign In to add comment