The following code displays 3 posts in a row which is in class item active.. but how do i display other post in custom post type class item so the carousel slides to display other 3 posts in a row like the image above..
<?php
$args = array( 'post_type' => 'testimonial','numberposts' => 3 );
$lastposts = get_posts( $args );
$index = 0;?>
<div class="carousel-reviews broun-block">
<div class="container">
<div id="carousel-reviews" class="carousel slide testi" data-ride="carousel">
<div class="carousel-inner">
<div class="item active">
<?php foreach($lastposts as $post) : setup_postdata($post); ++$index; ?>
<div class="col-md-4 col-sm-6">
<div class="block-text rel zmin">
<p><?php the_content();?></p>
<ins class="ab zmin sprite block"></ins>
</div>
<div class="person-text rel">
<a title="" href="#"><?php the_title();?></a>
<i><?php the_field('country');?></i>
</div>
</div>
<?php endforeach; ?>
</div>
Using while
<?php
$args = array('post_type' => 'testimonial',
'posts_per_page' =>-1,
'caller_get_posts'=> 3,
);
$the_query = new WP_Query($args);?>
<?php if ( $the_query->have_posts() ):?>
<?php $j = 0; ?>
<div class="carousel-reviews broun-block">
<div class="container">
<div id="carousel-reviews" class="carousel slide testi" data-ride="carousel">
<div class="carousel-inner">
<?php while ($the_query->have_posts()):$the_query->the_post();?>
<?php if($j == 0): ?>
<div class="item active">
<div class="col-md-4 col-sm-6">
<div class="block-text rel zmin">
<p><?php the_content();?></p>
<ins class="ab zmin sprite block"></ins>
</div>
<div class="person-text rel">
<a title="" href="#"><?php the_title();?></a>
<i><?php the_field('country');?></i>
</div>
</div>
</div>
<?php else: ?>
<div class="item ">
<div class="col-md-4 col-sm-6">
<div class="block-text rel zmin">
<p><?php the_content();?>
<ins class="ab zmin sprite block"></ins>
</div>
<div class="person-text rel">
<a title="" href="#"><?php the_title();?></a>
<i><?php the_field('country');?></i>
</div>
</div>
</div>
<?php endif; ?>
<?php $j++; ?>
<?php endwhile; endif; ?>
</div>
<a class="left carousel-control" href="#carousel-reviews" role="button" data-slide="prev">
<span class="fa fa-arrow-circle-left"></span>
</a>
<a class="right carousel-control" href="#carousel-reviews" role="button" data-slide="next">
<span class="fa fa-arrow-circle-right"></span>
</a>
</div>
</div>
</div>
The following code displays 3 posts in a row which is in class item active.. but how do i display other post in custom post type class item so the carousel slides to display other 3 posts in a row like the image above..
<?php
$args = array( 'post_type' => 'testimonial','numberposts' => 3 );
$lastposts = get_posts( $args );
$index = 0;?>
<div class="carousel-reviews broun-block">
<div class="container">
<div id="carousel-reviews" class="carousel slide testi" data-ride="carousel">
<div class="carousel-inner">
<div class="item active">
<?php foreach($lastposts as $post) : setup_postdata($post); ++$index; ?>
<div class="col-md-4 col-sm-6">
<div class="block-text rel zmin">
<p><?php the_content();?></p>
<ins class="ab zmin sprite block"></ins>
</div>
<div class="person-text rel">
<a title="" href="#"><?php the_title();?></a>
<i><?php the_field('country');?></i>
</div>
</div>
<?php endforeach; ?>
</div>
Using while
<?php
$args = array('post_type' => 'testimonial',
'posts_per_page' =>-1,
'caller_get_posts'=> 3,
);
$the_query = new WP_Query($args);?>
<?php if ( $the_query->have_posts() ):?>
<?php $j = 0; ?>
<div class="carousel-reviews broun-block">
<div class="container">
<div id="carousel-reviews" class="carousel slide testi" data-ride="carousel">
<div class="carousel-inner">
<?php while ($the_query->have_posts()):$the_query->the_post();?>
<?php if($j == 0): ?>
<div class="item active">
<div class="col-md-4 col-sm-6">
<div class="block-text rel zmin">
<p><?php the_content();?></p>
<ins class="ab zmin sprite block"></ins>
</div>
<div class="person-text rel">
<a title="" href="#"><?php the_title();?></a>
<i><?php the_field('country');?></i>
</div>
</div>
</div>
<?php else: ?>
<div class="item ">
<div class="col-md-4 col-sm-6">
<div class="block-text rel zmin">
<p><?php the_content();?>
<ins class="ab zmin sprite block"></ins>
</div>
<div class="person-text rel">
<a title="" href="#"><?php the_title();?></a>
<i><?php the_field('country');?></i>
</div>
</div>
</div>
<?php endif; ?>
<?php $j++; ?>
<?php endwhile; endif; ?>
</div>
<a class="left carousel-control" href="#carousel-reviews" role="button" data-slide="prev">
<span class="fa fa-arrow-circle-left"></span>
</a>
<a class="right carousel-control" href="#carousel-reviews" role="button" data-slide="next">
<span class="fa fa-arrow-circle-right"></span>
</a>
</div>
</div>
</div>
A div
with class="item"
is used for each carousel slide. But right now your foreach
loop is inside that div, not outside, so all of your posts are going into one slide.
So just change that bit to:
<div class="carousel-inner">
<?php foreach ($lastposts as $post) : setup_postdata ($post); ++$index; ?>
<div class="item<?php if ($index == 1) { echo ' active'; } ?>">
// Your post goes here
</div> <!-- item -->
<?php endforeach; ?>
</div> <!-- carousel-inner -->
And finally, change your query at the top to get as many posts as you want in the carousel, such as 10:
$args = array( 'post_type' => 'testimonial','numberposts' => 10 );