0
votes

$data = new WP_Query( array( 'post_type' => 'myposttype' ,'category' => 1 , 'posts_per_page' => -1,) ); if ( $the_query->have_posts() ) {

  while ( $the_query->have_posts() ) {
    $data->the_post();

    echo '<li data-target="#id" data-slide-to="8" class="new"></li>';

  }
  wp_reset_postdata(); 
}  ?>

The above code is displaying Carousel Indicator equals to no of posts I want it to display one indicator after 4 please help where I am wrong

This doesnot show the result please help

1

1 Answers

1
votes
    <ol class="carousel-indicators">
<?php $the_query   = new WP_Query( array( 'post_type' => 'myposttype' ,'category' => 1 , 'posts_per_page' => -1,) ); 
if ( $the_query->have_posts() ) {
  $j = 0;
  while ( $the_query->have_posts() ) {
    $j++;

    $the_query->the_post();

    }  ?>
   <li data-target="#myCarousel" data-slide-to=" <?php echo $j ?>" class=" <?php if($j==1) {echo 'active';} ?>"></li>';
  <?php}
  wp_reset_postdata(); 
}  ?>
</ol> 

try this