Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function foodie_world_post_page_category_slider() {
- $quantity = get_theme_mod( 'foodie_world_slider_number', 4 );
- $no_of_post = 0; // for number of posts
- $post_list = array();// list of valid post/page ids
- $type = get_theme_mod( 'foodie_world_slider_type', 'demo' );
- $show_content = get_theme_mod( 'foodie_world_slider_content_show', 'hide-content' );
- $output = '';
- $args = array(
- 'post_type' => 'any',
- 'orderby' => 'post__in',
- 'ignore_sticky_posts' => 1, // ignore sticky posts
- );
- //Get valid number of posts
- if ( 'post' === $type || 'page' === $type ) {
- for ( $i = 1; $i <= $quantity; $i++ ) {
- $post_id = '';
- if ( 'post' === $type ) {
- $post_id = get_theme_mod( 'foodie_world_slider_post_' . $i );
- } elseif ( 'page' === $type ) {
- $post_id = get_theme_mod( 'foodie_world_slider_page_' . $i );
- }
- if ( $post_id && '' !== $post_id ) {
- $post_list = array_merge( $post_list, array( $post_id ) );
- $no_of_post++;
- }
- }
- $args['post__in'] = $post_list;
- } elseif ( 'category' === $type ) {
- $no_of_post = $quantity;
- $args['category__in'] = get_theme_mod( 'foodie_world_slider_select_category' );
- $args['post_type'] = 'post';
- }
- if ( ! $no_of_post ) {
- return;
- }
- $args['posts_per_page'] = $no_of_post;
- $loop = new WP_Query( $args );
- while ( $loop->have_posts() ) :
- $loop->the_post();
- $title_attribute = the_title_attribute( 'echo=0' );
- if ( 0 === $loop->current_post ) {
- $classes = 'post post-' . esc_attr( get_the_ID() ) . ' hentry slides displayblock';
- } else {
- $classes = 'post post-' . esc_attr( get_the_ID() ) . ' hentry slides displaynone';
- }
- // Default value if there is no featurd image or first image.
- $image_url = trailingslashit( esc_url ( get_template_directory_uri() ) ) . 'assets/images/no-thumb-1920x822.jpg';
- if ( has_post_thumbnail() ) {
- $image_url = get_the_post_thumbnail_url( get_the_ID(), 'foodie-world-slider' );
- } else {
- // Get the first image in page, returns false if there is no image.
- $first_image_url = foodie_world_get_first_image( get_the_ID(), 'foodie-world-slider', '', true );
- // Set value of image as first image if there is an image present in the page.
- if ( $first_image_url ) {
- $image_url = $first_image_url;
- }
- }
- $more_tag_text = get_theme_mod( 'foodie_world_excerpt_more_text', esc_html__( 'Continue reading', 'foodie-world-pro' ) );
- $output .= '
- <div class="post-slide">
- <article class="' . $classes . '">';
- $output .= '
- <div class="slider-image">
- <a href="' . esc_url( get_permalink() ) . '" title="' . $title_attribute . '">
- <img src="' . esc_url( $image_url ) . '" class="wp-post-image" alt="' . $title_attribute . '">
- </a>
- </div><!-- .slider-image -->
- <div class="entry-container">';
- if ( 'post' === get_post_type() ) {
- $output .= '<div class="entry-meta">' . foodie_world_entry_category( false ) . '</div>';
- }
- $output .= the_title( '<header class="entry-header"><h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '">', '</a></h2></header>', false );
- $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>';
- $output .= '
- </div><!-- .entry-container -->
- </article><!-- .slides -->
- </div><!-- .post-slide -->';
- endwhile;
- wp_reset_postdata();
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement