Advertisement
Guest User

slider-readmore-text.php

a guest
Mar 14th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. function foodie_world_post_page_category_slider() {
  2. $quantity = get_theme_mod( 'foodie_world_slider_number', 4 );
  3. $no_of_post = 0; // for number of posts
  4. $post_list = array();// list of valid post/page ids
  5. $type = get_theme_mod( 'foodie_world_slider_type', 'demo' );
  6. $show_content = get_theme_mod( 'foodie_world_slider_content_show', 'hide-content' );
  7. $output = '';
  8.  
  9. $args = array(
  10. 'post_type' => 'any',
  11. 'orderby' => 'post__in',
  12. 'ignore_sticky_posts' => 1, // ignore sticky posts
  13. );
  14.  
  15. //Get valid number of posts
  16. if ( 'post' === $type || 'page' === $type ) {
  17. for ( $i = 1; $i <= $quantity; $i++ ) {
  18. $post_id = '';
  19.  
  20. if ( 'post' === $type ) {
  21. $post_id = get_theme_mod( 'foodie_world_slider_post_' . $i );
  22. } elseif ( 'page' === $type ) {
  23. $post_id = get_theme_mod( 'foodie_world_slider_page_' . $i );
  24. }
  25.  
  26. if ( $post_id && '' !== $post_id ) {
  27. $post_list = array_merge( $post_list, array( $post_id ) );
  28.  
  29. $no_of_post++;
  30. }
  31. }
  32.  
  33. $args['post__in'] = $post_list;
  34. } elseif ( 'category' === $type ) {
  35. $no_of_post = $quantity;
  36.  
  37. $args['category__in'] = get_theme_mod( 'foodie_world_slider_select_category' );
  38.  
  39. $args['post_type'] = 'post';
  40. }
  41.  
  42. if ( ! $no_of_post ) {
  43. return;
  44. }
  45.  
  46. $args['posts_per_page'] = $no_of_post;
  47.  
  48. $loop = new WP_Query( $args );
  49.  
  50. while ( $loop->have_posts() ) :
  51. $loop->the_post();
  52.  
  53. $title_attribute = the_title_attribute( 'echo=0' );
  54.  
  55. if ( 0 === $loop->current_post ) {
  56. $classes = 'post post-' . esc_attr( get_the_ID() ) . ' hentry slides displayblock';
  57. } else {
  58. $classes = 'post post-' . esc_attr( get_the_ID() ) . ' hentry slides displaynone';
  59. }
  60.  
  61. // Default value if there is no featurd image or first image.
  62. $image_url = trailingslashit( esc_url ( get_template_directory_uri() ) ) . 'assets/images/no-thumb-1920x822.jpg';
  63.  
  64. if ( has_post_thumbnail() ) {
  65. $image_url = get_the_post_thumbnail_url( get_the_ID(), 'foodie-world-slider' );
  66. } else {
  67. // Get the first image in page, returns false if there is no image.
  68. $first_image_url = foodie_world_get_first_image( get_the_ID(), 'foodie-world-slider', '', true );
  69.  
  70. // Set value of image as first image if there is an image present in the page.
  71. if ( $first_image_url ) {
  72. $image_url = $first_image_url;
  73. }
  74. }
  75.  
  76. $more_tag_text = get_theme_mod( 'foodie_world_excerpt_more_text', esc_html__( 'Continue reading', 'foodie-world-pro' ) );
  77.  
  78. $output .= '
  79. <div class="post-slide">
  80. <article class="' . $classes . '">';
  81. $output .= '
  82. <div class="slider-image">
  83. <a href="' . esc_url( get_permalink() ) . '" title="' . $title_attribute . '">
  84. <img src="' . esc_url( $image_url ) . '" class="wp-post-image" alt="' . $title_attribute . '">
  85. </a>
  86. </div><!-- .slider-image -->
  87. <div class="entry-container">';
  88.  
  89. if ( 'post' === get_post_type() ) {
  90. $output .= '<div class="entry-meta">' . foodie_world_entry_category( false ) . '</div>';
  91. }
  92.  
  93. $output .= the_title( '<header class="entry-header"><h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '">', '</a></h2></header>', false );
  94.  
  95. $output .= '<span class="more-button"><a href="' . esc_url( get_permalink() ) . '" class="more-link">' . wp_kses_data( esc_html__( 'Shop Now', 'foodie-world-pro' ) ) . '</a></span>';
  96.  
  97. $output .= '
  98. </div><!-- .entry-container -->
  99. </article><!-- .slides -->
  100. </div><!-- .post-slide -->';
  101. endwhile;
  102.  
  103. wp_reset_postdata();
  104.  
  105. return $output;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement