Guest User

Untitled

a guest
May 16th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.65 KB | None | 0 0
  1. function woo_slider_biz( $args = null ) {
  2.  
  3. global $woo_options, $post;
  4.  
  5. // This is where our output will be added.
  6. $html = '';
  7.  
  8. // Default slider settings.
  9. $defaults = array(
  10. 'id' => 'loopedSlider',
  11. 'echo' => true,
  12. 'excerpt_length' => '15',
  13. 'pagination' => false,
  14. 'width' => '940',
  15. 'height' => '350',
  16. 'order' => 'ASC',
  17. 'posts_per_page' => '5',
  18. 'slide_page' => 'all',
  19. 'use_slide_page' => false
  20. );
  21.  
  22. // Setup the "Slide Page", if one is set.
  23. if ( isset( $post->ID ) ) {
  24. $slide_page = 'all';
  25. $stored_slide_page = get_post_meta( $post->ID, '_slide-page', true );
  26.  
  27. if ( $stored_slide_page != '' && $stored_slide_page != 'all' ) {
  28. $slide_page = $stored_slide_page;
  29. $defaults['use_slide_page'] = true; // Instruct the slider to apply the necessary conditional.
  30. $defaults['slide_page'] = $slide_page;
  31. }
  32. }
  33.  
  34. // Setup height of slider.
  35. $height = $woo_options['woo_slider_biz_height'];
  36. if ( $height != '' ) { $defaults['height'] = $height; }
  37.  
  38. // Setup width of slider and images.
  39. $layout = $woo_options['woo_layout'];
  40. if ( !$layout )
  41. $layout = get_option( 'woo_layout' );
  42. $layout_width = get_option('woo_layout_width');
  43.  
  44. // Setup the number of posts to show.
  45. $posts_per_page = $woo_options['woo_slider_biz_number'];
  46. if ( $posts_per_page != '' ) { $defaults['posts_per_page'] = $posts_per_page; }
  47.  
  48. // Setup the order of posts.
  49. $post_order = $woo_options['woo_slider_biz_order'];
  50. if ( $post_order != '' ) { $defaults['order'] = $post_order; }
  51.  
  52. // Setup the excerpt length.
  53. if ( isset($woo_options['woo_slider_biz_excerpt_length']) ) {
  54. $excerpt_length = $woo_options['woo_slider_biz_excerpt_length'];
  55. if ( $excerpt_length != '' ) { $defaults['excerpt_length'] = $excerpt_length; }
  56. }
  57.  
  58. $width = intval( $layout_width );
  59.  
  60. if ( $width > 0 && $args['width'] == '' ) { $defaults['width'] = $width; }
  61.  
  62. // Merge the arguments with defaults.
  63. $args = wp_parse_args( $args, $defaults );
  64.  
  65. if ( ( ( isset($args['width']) ) && ( ( $args['width'] <= 0 ) || ( $args['width'] == '') ) ) || ( !isset($args['width']) ) ) { $args['width'] = '100'; }
  66. if ( ( isset($args['height']) ) && ( $args['height'] <= 0 ) ) { $args['height'] = '100'; }
  67.  
  68. // Allow child themes/plugins to filter these arguments.
  69. $args = apply_filters( 'woo_biz_slider_args', $args );
  70.  
  71. // Setup slider page id's
  72. $query_args = array(
  73. 'post_type' => 'slide',
  74. 'order' => $args['order'],
  75. 'orderby' => 'date',
  76. 'posts_per_page' => $args['posts_per_page']
  77. );
  78.  
  79. if ( $args['use_slide_page'] == true ) {
  80.  
  81. $query_args['tax_query'] = array( array(
  82. 'taxonomy' => 'slide-page',
  83. 'field' => 'slug',
  84. 'terms' => $args['slide_page']
  85. ) );
  86.  
  87. }
  88.  
  89. $slide_query = new WP_Query( $query_args );
  90.  
  91. if ( ( ! $slide_query->have_posts() ) ) {
  92. echo '<p class="note">' . __( 'Please add some slider posts using the Slide custom post type.', 'woothemes' ) . '</p>';
  93. return;
  94. }
  95.  
  96. if ( ( $slide_query->found_posts < 1 ) ) {
  97. echo '<p class="note">' . __( 'Please note that this slider requires 2 or more slides in order to function. Please assign another slide.', 'woothemes' ) . '</p>';
  98. return;
  99. }
  100.  
  101. // Setup the slider CSS class.
  102. $slider_css = '';
  103.  
  104. if ( @$woo_options['woo_slider_pagination'] == 'true' ) {
  105. $slider_css = ' class="has-pagination"';
  106. }
  107.  
  108. // Begin setting up HTML output.
  109.  
  110. if ( @$woo_options['woo_slider_autoheight'] != 'true' ) {
  111. $html .= '<div id="' . $args['id'] . '"' . $slider_css . ' style="height:' . $args['height'] . 'px">' . "\n";
  112. $html .= '<div class="container" style="height:' . $args['height'] . 'px">' . "\n";
  113. } else {
  114. $html .= '<div id="' . $args['id'] . '"' . $slider_css . ' style="height:auto;">' . "\n";
  115. $html .= '<div class="container" style="height:auto;">' . "\n";
  116. }
  117.  
  118.  
  119. if ( @$woo_options['woo_slider_autoheight'] != 'true' )
  120. $html .= '<div class="slides" style="height:' . $args['height'] . 'px">' . "\n";
  121. else
  122. $html .= '<div class="slides">' . "\n";
  123.  
  124. if ( $slide_query->have_posts() ) { $count = 0; while ( $slide_query->have_posts() ) { $slide_query->the_post(); global $post; $count++;
  125.  
  126. $styles = 'width: ' . $args['width'] . 'px;';
  127. if ( $count >= 2 ) { $styles .= ' display:none;'; }
  128.  
  129. $html .= '<div id="slide-' . $count . '" class="slide" style="' . $styles . '">' . "\n";
  130.  
  131. $type = get_post_meta( $post->ID, 'image', true );
  132.  
  133. if ( $type ) {
  134. $url = get_post_meta( $post->ID, 'url', true );
  135.  
  136. if ( $url ) {
  137. $html .= '<a href="' . $url . '" title="' . the_title_attribute( array( 'echo' => 0 ) ) . '">' . woo_image('width=784&height=452&link=img&return=true') . '</a>' . "\n";
  138. } else {
  139. $html .= woo_image( 'width=784&height=452&link=img&return=true' );
  140. }
  141.  
  142. $html .= '<div class="content">' . "\n";
  143.  
  144. if ( $woo_options['woo_slider_biz_title'] == 'true' ) {
  145. if ( $url ) {
  146. $html .= '<div class="title"><h2 class="title"><a href="' . $url . '">' . get_the_title( $post->ID ) . '</a></h2></div>' . "\n";
  147.  
  148. } else {
  149. $html .= '<div class="title"><h2 class="title">' . get_the_title( $post->ID ) . '</h2></div>' . "\n";
  150.  
  151. }
  152. }
  153. $content = get_the_content($post->ID);
  154. $content = do_shortcode($content);
  155.  
  156. $html .= '<div class="excerpt">' . wpautop( $content ) . '</div>' . "\n";
  157. $html .= '</div>' . "\n";
  158.  
  159. } else {
  160.  
  161. $content = get_the_content($post->ID);
  162. $content = do_shortcode($content);
  163.  
  164. $html .= '<div class="entry">' . wpautop( $content ) . '</div>' . "\n";
  165.  
  166. }
  167.  
  168. $html .= '</div>' . "\n";
  169.  
  170. } // End WHILE Loop
  171.  
  172. } // End IF Statement
  173.  
  174. $html .= '</div><!-- /.slides -->' . "\n";
  175. $html .= '</div><!-- /.container --> ' . "\n";
  176.  
  177. $html .= '<a href="#" class="previous"><img src="' . get_template_directory_uri() . '/images/btn-prev-slider.png" alt="<" /></a>' . "\n";
  178. $html .= '<a href="#" class="next"><img src="' . get_template_directory_uri() . '/images/btn-next-slider.png" alt=">" /></a>' . "\n";
  179.  
  180.  
  181. $html .= '</div><!-- /#' . $args['id'] . ' -->' . "\n";
  182.  
  183. if ( $args['echo'] ) {
  184. echo $html;
  185. }
  186.  
  187. return $html;
  188.  
  189. } // End woo_slider_biz()
Add Comment
Please, Sign In to add comment