I am trying to make a slider cycle through the custom posts in Wordpress, displaying 4 at a time. I would like it to cycle through the posts and just loop back to the first one when it has reached the last post. My code is:
<div id="myCarousel" class="carousel slide">
<!-- Carousel items -->
<div class="carousel-inner">
<div class="item active">
<div class="row">
<?php
$args = array(
'posts_per_page' => '4',
'post_type' => 'dogs',
);
$myDogs = new WP_Query( $args ); ?>
<?php while ( $myDogs->have_posts() ) : $myDogs->the_post();?>
<div id="sl-cont" class="col-sm-12 col-md-3 col-lg-3">
<div class="well">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('slider-size'); ?></a>
<div class="dog-caption">
<p><span class="title"><?php the_title(); ?></span><br/>
<?php the_excerpt(); ?><br/>
<a href="<?php the_permalink() ?>">Read more >> </a></p>
</div>
</div><!--end of well-->
</div><!--end of container-->
<?php endwhile;
wp_reset_postdata();?>
</div>
<!--/row-->
</div>
<!--/item-->
<div class="item">
<div class="row">
<?php
$args = array(
'posts_per_page' => '4',
'post_type' => 'dogs',
'offset' => 1
);
$myDogs = new WP_Query( $args ); ?>
<?php while ( $myDogs->have_posts() ) : $myDogs->the_post();?>
<div id="sl-cont" class="col-sm-12 col-md-3 col-lg-3">
<div class="well">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('slider-size'); ?></a>
<div class="dog-caption">
<p><span class="title"><?php the_title(); ?></span><br/>
<?php the_excerpt(); ?><br/>
<a href="<?php the_permalink() ?>">Read more >> </a></p>
</div>
</div><!--end of well-->
</div><!--end of container-->
<?php endwhile;
wp_reset_postdata();?>
</div>
<!--/row-->
</div>
<!--/item-->
</div> <!--/carousel-inner-->
<a class="left carousel-control" href="#myCarousel" data-slide="prev"><img src="<?php bloginfo('template_directory'); ?>/img/left-paw.png"> </a>
<a class="right carousel-control" href="#myCarousel" data-slide="next"><img src="<?php bloginfo('template_directory'); ?>/img/right-paw.png"></a>
`
Can anyone help?