pash
2/17/2020 - 1:07 PM

Slick Custom Post Slider (In Shortcode)

function portfolio_slider()
   {
        ob_start();

    //  WP_Query arguments
    $args = array (
        'post_type'              => array( 'case-study' ),

    );

    // The Query
    $query_slider = new WP_Query( $args );

    // The Loop
    if ( $query_slider->have_posts() ) {
        echo '<div class="variable-width">';
        while ( $query_slider->have_posts() ) {
            $query_slider->the_post();
            $featured_image_url = wp_get_attachment_url( get_post_thumbnail_id($query_slider->ID) ); ?>


          <div class="case-study-container" style="background: url('<?php echo $featured_image_url ?>')">
            <div class="case-study-title">Hello!</div>
            <div class="case-study-blurb">Blurb, blurb, blurb, blurb, blurb!</div>
          </div>



      <?  }
        echo '</div>';
    } else {
        // no posts found
    }

    // Restore original Post Data
    wp_reset_postdata();


       return ob_get_clean();
   }
   add_shortcode( 'portfolio_slider', 'portfolio_slider' );