Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.77 KB | None | 0 0
  1. <?php
  2. /**
  3. * The template for displaying the Slider
  4. *
  5. * @package Catch Themes
  6. * @subpackage Helena
  7. * @since Helena 0.1
  8. */
  9.  
  10.  
  11.  
  12. if ( !function_exists( 'helena_logo_slider' ) ) :
  13. /**
  14. * Add slider.
  15. *
  16. * @uses action hook helena_before_content.
  17. *
  18. * @since Helena 0.1
  19. */
  20. function helena_logo_slider() {
  21. //helena_flush_transients();
  22. global $wp_query;
  23.  
  24. $enable_slider = apply_filters( 'helena_get_option', 'logo_slider_option' );
  25. $layout = apply_filters( 'helena_get_option', 'logo_slider_visible_items' );
  26. $slider_type = apply_filters( 'helena_get_option', 'logo_slider_type' );
  27.  
  28. // Get Page ID outside Loop
  29. $page_id = $wp_query->get_queried_object_id();
  30.  
  31. // Front page displays in Reading Settings
  32. $page_on_front = get_option('page_on_front') ;
  33. $page_for_posts = get_option('page_for_posts');
  34.  
  35. if ( 'entire-site' == $enable_slider || ( ( is_front_page() || ( is_home() && $page_for_posts != $page_id ) ) && 'homepage' == $enable_slider ) ) {
  36. if ( ( !$output = get_transient( 'helena_logo_slider' ) ) ) {
  37. echo '<!-- refreshing cache -->';
  38. $class[] = 'section-title';
  39.  
  40. if ( 1 == $layout ) {
  41. $class[] = 'one-column';
  42. }
  43. elseif ( 2 == $layout ) {
  44. $class[] = 'two-columns';
  45. }
  46. elseif ( 3 == $layout ) {
  47. $class[] = 'three-columns';
  48. }
  49. elseif ( 4 == $layout ) {
  50. $class[] = 'four-columns';
  51. }
  52. elseif ( 5 == $layout ) {
  53. $class[] = 'five-columns';
  54. }
  55.  
  56.  
  57. $class[] = $slider_type;
  58.  
  59. $output = '
  60. <section class="'. esc_attr( implode( ' ', $class ) ) .'" id="logo-slider">
  61. <div class="wrapper">';
  62. if ( 'demo' == $slider_type ) {
  63. $title = esc_html__( 'Our Associates', 'helena' );
  64. }
  65. else {
  66. $title = apply_filters( 'helena_get_option', 'logo_slider_title' );
  67. }
  68.  
  69. if ( $title ) {
  70. $output .= '<h2 id="logo-slider-title" class="section-title">' . esc_html( $title ) . '</h2>';
  71. }
  72.  
  73. $output .= '
  74. <div class="logo_slider_content_slider_wrap cycle-slideshow"
  75. data-cycle-log="false"
  76. data-cycle-pause-on-hover="true"
  77. data-cycle-swipe="true"
  78. data-cycle-fx=carousel
  79. data-cycle-carousel-fluid=true
  80. data-cycle-carousel-visible="'. absint( apply_filters( 'helena_get_option', 'logo_slider_visible_items' ) ) .'"
  81.  
  82. data-cycle-speed="'. esc_attr( apply_filters( 'helena_get_option', 'logo_slider_transition_length' ) ) * 1000 .'"
  83. data-cycle-timeout="'. esc_attr( apply_filters( 'helena_get_option', 'logo_slider_transition_delay' ) ) * 1000 .'"
  84. data-cycle-slides="> article"
  85. >';
  86.  
  87. if ( 'demo' == $slider_type ) {
  88. $output .= helena_demo_logo_slider();
  89. }
  90. else {
  91. $output .= helena_post_page_category_logo_slider();
  92. }
  93.  
  94. $output .= '
  95. </div><!-- .logo_slider_content_slider_wrap.cycle-slideshow -->
  96. </div><!-- .wrapper -->
  97. </section><!-- #feature-slider -->';
  98.  
  99. set_transient( 'helena_logo_slider', $output, 86940 );
  100. }
  101. echo $output;
  102. }
  103. }
  104. endif;
  105. add_action( 'helena_before_content', 'helena_logo_slider', 70 );
  106.  
  107.  
  108. if ( ! function_exists( 'helena_demo_logo_slider' ) ) :
  109. /**
  110. * This function to display featured posts content
  111. *
  112. * @get the data value from customizer options
  113. *
  114. * @since Helena 0.1
  115. *
  116. */
  117. function helena_demo_logo_slider() {
  118. return '
  119. <article id="featured-post-1" class="post hentry post-demo">
  120. <figure class="featured-content-image">
  121. <a href="#" rel="bookmark">
  122. <img alt="Demo Logo One" class="wp-post-image" src="'.get_template_directory_uri() . '/images/logo1.png" />
  123. </a>
  124. </figure>
  125. </article>
  126.  
  127. <article id="featured-post-2" class="post hentry post-demo">
  128. <figure class="featured-content-image">
  129. <a href="#" rel="bookmark">
  130. <img alt="Demo Logo Two" class="wp-post-image" src="'.get_template_directory_uri() . '/images/logo2.png" />
  131. </a>
  132. </figure>
  133. </article>
  134.  
  135. <article id="featured-post-3" class="post hentry post-demo">
  136. <figure class="featured-content-image">
  137. <a href="#" rel="bookmark">
  138. <img alt="Demo Logo Three" class="wp-post-image" src="'.get_template_directory_uri() . '/images/logo3.png" />
  139. </a>
  140. </figure>
  141. </article>
  142.  
  143. <article id="featured-post-4" class="post hentry post-demo">
  144. <figure class="featured-content-image">
  145. <a href="#" rel="bookmark">
  146. <img alt="Demo Logo Four" class="wp-post-image" src="'.get_template_directory_uri() . '/images/logo4.png" />
  147. </a>
  148. </figure>
  149. </article>
  150.  
  151. <article id="featured-post-5" class="post hentry post-demo">
  152. <figure class="featured-content-image">
  153. <a href="#" rel="bookmark">
  154. <img alt="Demo Logo Five" class="wp-post-image" src="'.get_template_directory_uri() . '/images/logo5.png" />
  155. </a>
  156. </figure>
  157. </article>';
  158. }
  159. endif; // helena_demo_logo_slider
  160.  
  161.  
  162. if ( ! function_exists( 'helena_post_page_category_logo_slider' ) ) :
  163. /**
  164. * This function to display hero posts content
  165. *
  166. * @param $options: helena_theme_options from customizer
  167. *
  168. * @since Helena 0.1
  169. */
  170. function helena_post_page_category_logo_slider() {
  171. $output = '';
  172. $no_of_post = 0; // for number of posts
  173. $post_list = array();// list of valid post/page ids
  174. $type = apply_filters( 'helena_get_option', 'logo_slider_type' );
  175. $quantity = apply_filters( 'helena_get_option', 'logo_slider_number' );
  176.  
  177. $args = array(
  178. 'post_type' => 'any',
  179. 'orderby' => 'post__in',
  180. 'ignore_sticky_posts' => 1 // ignore sticky posts
  181. );
  182.  
  183. //Get valid number of posts
  184. if ( 'post' == $type || 'page' == $type ) {
  185. for( $i = 1; $i <= $quantity; $i++ ){
  186. $post_id = '';
  187.  
  188. if ( 'post' == $type ) {
  189. $post_id = apply_filters( 'helena_get_option', 'logo_slider_post_' . $i );
  190. }
  191. elseif ( 'page' == $type ) {
  192. $post_id = apply_filters( 'helena_get_option', 'logo_slider_page_' . $i );
  193. }
  194.  
  195. if ( $post_id && '' != $post_id ) {
  196. $post_list = array_merge( $post_list, array( $post_id ) );
  197.  
  198. $no_of_post++;
  199. }
  200. }
  201.  
  202. $args['post__in'] = $post_list;
  203. }
  204. elseif ( 'category' == $type ) {
  205. $no_of_post = $quantity;
  206. $args['category__in'] = apply_filters( 'helena_get_option', 'logo_slider_select_category' );
  207. }
  208.  
  209. if ( 0 == $no_of_post ) {
  210. return;
  211. }
  212.  
  213. $args['posts_per_page'] = $no_of_post;
  214. $get_hero_posts = new WP_Query( $args );
  215.  
  216. while ( $get_hero_posts->have_posts() ) {
  217. $get_hero_posts->the_post();
  218.  
  219. $title_attribute = the_title_attribute( 'echo=0' );
  220.  
  221. $output .= '
  222. <article id="post-' . esc_attr( get_the_ID() ) . '" class="post-' . esc_attr( get_the_ID() ) . ' hentry">';
  223.  
  224. //Default value if there is no first image
  225. $image = '<img class="wp-post-image" src="'.get_template_directory_uri().'/images/no-featured-image-150x150.jpg" >';
  226.  
  227. if ( has_post_thumbnail() ) {
  228. $image = get_the_post_thumbnail( get_the_ID(), 'full', array( 'title' => $title_attribute, 'alt' => $title_attribute ) );
  229. }
  230. else {
  231. //Get the first image in page, returns false if there is no image
  232. $first_image = helena_get_first_image( get_the_ID(), 'full', array( 'title' => $title_attribute, 'alt' => $title_attribute ) );
  233.  
  234. //Set value of image as first image if there is an image present in the page
  235. if ( '' != $first_image ) {
  236. $image = $first_image;
  237. }
  238. }
  239. $output .= '
  240. <figure class="featured-content-image">
  241. <a href="' . esc_url( get_permalink() ) . '" title="' . $title_attribute . '">
  242. '. $image .'
  243. </a>
  244. </figure>';
  245.  
  246. $output .= '
  247. </article><!-- .post-' . esc_attr( get_the_ID() ) . ' -->';
  248. } //endwhile
  249.  
  250. wp_reset_postdata();
  251.  
  252. return $output;
  253. }
  254. endif; // helena_post_page_category_logo_slider
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement