0

I have 7 services in a page. All 7 services have featured images. I want to show all the 7 images and content in a slideshow.

 $args = array(
   'post_type' => 'page',
   'post__in'      => $myarray
);

// The Query<br>
$the_query = new WP_Query( $args );

How can I show the featured image in the slide show. Please guide me.

0
1

this is a fairly broad question since there are multiple solutions depending on your exact needs. My method might involve:

  • Setup normal 'Loop'
  • in each iteration grab the featured image using: wp_get_attachment_image_src( get_post_thumbnail_id( post->ID ), 'large' );
  • build an unordered list of images
  • Use a plugin that works with UL listitems to generated a slideshow with the desired features

That's pretty much it. Can't test this but might end up looking like:

$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
    echo '<div class="flexslider"><ul class="slides">'; 
    while ( $the_query->have_posts() ) {
         $the_query->the_post();
         echo '<li><img src="' . wp_get_attachment_image_src( get_post_thumbnail_id( post->ID ), 'large' ) . '" /></li>';
    }
    echo '</ul></div>';
}

And then use maybe

Flexslider2

0

You will need to create a WP query to grab posts and then put them in a Slider like Flex Slider to display them in a slider.Here is the query :-

<?php  
        $args = array(
            'post_status' => 'publish',
            'post_type' => 'carousel',
            'carousel-category' => 'your-category',
            'posts_per_page' => 7
        );
        $recentPosts = new WP_Query( $args );
        if ( $recentPosts->have_posts() ) : ?> 

Now grab the featured image using the following code (in loop):-

<?php 
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
    the_post_thumbnail();
} 
?> 

You will need to them inside Div elements to create a carousel.Here is a tutorial that you can use for better understanding :- http://www.wordpressauthors.com/wordpress-development/display-a-carousel-of-most-recent-posts/

Hope that helps. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.