Advertisement
Guest User

random-slider.php

a guest
Apr 16th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. function lucida_post_page_category_slider( $options ) {
  2. global $post;
  3.  
  4. $quantity = $options['featured_slider_number'];
  5. $no_of_post = 0; // for number of posts
  6. $post_list = array();// list of valid post/page ids
  7. $type = $options['featured_slider_type'];
  8. $show_content = $options['featured_slider_content_show'];
  9. $output = '';
  10.  
  11. $args = array(
  12. 'post_type' => 'any',
  13. 'orderby' => 'rand(x)',
  14. 'order' => 'DESC',
  15. 'ignore_sticky_posts' => 1 // ignore sticky posts
  16. );
  17.  
  18. //Get valid number of posts
  19. if( 'post' == $type || 'page' == $type ) {
  20. for( $i = 1; $i <= $quantity; $i++ ){
  21. $post_id = '';
  22.  
  23. if( 'post' == $type ) {
  24. $post_id = isset( $options['featured_slider_post_' . $i] ) ? $options['featured_slider_post_' . $i] : false;
  25. }
  26. elseif( 'page' == $type ) {
  27. $post_id = isset( $options['featured_slider_page_' . $i] ) ? $options['featured_slider_page_' . $i] : false;
  28. }
  29.  
  30. if ( $post_id && '' != $post_id ) {
  31. $post_list = array_merge( $post_list, array( $post_id ) );
  32.  
  33. $no_of_post++;
  34. }
  35. }
  36.  
  37. $args['post__in'] = $post_list;
  38. }
  39. elseif( 'category' == $type ) {
  40. $no_of_post = $quantity;
  41.  
  42. $args['category__in'] = $options['featured_slider_select_category'];
  43. }
  44.  
  45. if ( 0 == $no_of_post ) {
  46. return;
  47. }
  48.  
  49. $args['posts_per_page'] = $no_of_post;
  50.  
  51. $loop = new WP_Query( $args );
  52. $i=0;
  53. while ( $loop->have_posts()) : $loop->the_post(); $i++;
  54.  
  55. $title_attribute = the_title_attribute( 'echo=0' );
  56.  
  57. if ( $i == 1 ) {
  58. $classes = 'post post-'.$post->ID.' hentry slides displayblock';
  59. } else {
  60. $classes = 'post post-'.$post->ID.' hentry slides displaynone';
  61. }
  62.  
  63. $output .= '
  64. <article class="' . $classes . '">
  65. <figure class="slider-image">';
  66. if ( has_post_thumbnail() ) {
  67. $output .= '<a title="' . $title_attribute . '" href="' . esc_url( get_permalink() ) . '">
  68. '. get_the_post_thumbnail( $post->ID, 'lucida-slider', array( 'title' => $title_attribute, 'alt' => $title_attribute, 'class' => 'attached-post-image' ) ).'
  69. </a>';
  70. }
  71. else {
  72. //Default value if there is no first image
  73. $lucida_image = '<img class="wp-post-image" src="'.esc_url( get_template_directory_uri() ).'/images/gallery/no-featured-image-1920x800.jpg" >';
  74.  
  75. //Get the first image in page, returns false if there is no image
  76. $lucida_first_image = lucida_get_first_image( $post->ID, 'lucida-slider', array( 'title' => $title_attribute, 'alt' => $title_attribute, 'class' => 'attached-post-image' ) );
  77.  
  78. //Set value of image as first image if there is an image present in the page
  79. if ( '' != $lucida_first_image ) {
  80. $lucida_image = $lucida_first_image;
  81. }
  82.  
  83. $output .= '<a title="' . $title_attribute . '" href="' . esc_url( get_permalink() ) . '">
  84. '. $lucida_image .'
  85. </a>';
  86. }
  87.  
  88. $output .= '
  89. </figure><!-- .slider-image -->
  90. <div class="slider-content-wrapper">
  91. <div class="entry-container">
  92. <header class="entry-header">
  93. <h2 class="entry-title">
  94. <a title="' . $title_attribute . '" href="' . esc_url( get_permalink() ) . '">'.the_title( '<span>','</span>', false ).'</a>
  95. </h2>
  96. <p class="entry-meta">' . lucida_page_post_meta() . '</p><!-- .entry-meta -->
  97. </header>
  98. ';
  99.  
  100. if ( 'excerpt' == $show_content ) {
  101. $excerpt = get_the_excerpt();
  102.  
  103. $output .= '<div class="entry-summary"><p>' . $excerpt . '</p></div><!-- .entry-summary -->';
  104. } elseif ( 'full-content' == $show_content ) {
  105. $content = apply_filters( 'the_content', get_the_content() );
  106. $content = str_replace( ']]>', ']]&gt;', $content );
  107. $output .= '<div class="entry-content">' . wp_kses_post( $content ) . '</div><!-- .entry-content -->';
  108. }
  109.  
  110. $output .= '
  111. </div><!-- .entry-container -->
  112. </div><!-- .slider-content-wrapper -->
  113. </article><!-- .slides -->';
  114. endwhile;
  115.  
  116. wp_reset_postdata();
  117.  
  118. return $output;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement