0

Im using a loop to make a slider. My code is

<?php 
query_posts( array( 'post_type' => 'my_gallery', 'author'=>$author->ID ) );

while( have_posts() ) : 
    the_post(); 
    $imagethum = eh_postImage(115, 70); 
?>
<a data-slide-index="0" href=""><?php echo $imagethum; ?></a>
<?php endwhile; ?>

I need the data-slide-index="0" attribute to increase by 1 for every post in the loop so the output appears as...

<a data-slide-index="0" href="">
<a data-slide-index="1" href="">
<a data-slide-index="2" href="">
<a data-slide-index="3" href="">
<a data-slide-index="4" href="">
<a data-slide-index="5" href="">

after printed

Some kind of for each statement here?

1
  • also I strongly recommend against using query_posts, it is never a good idea, instead WP_Query objects, the pre_get_posts filter or the get_posts function are your friend
    – Tom J Nowell
    May 9, 2013 at 11:01

1 Answer 1

1

try yo use the build-in loop counter:

  <a data-slide-index="<?php echo $wp_query->current_post; ?>" href=""><?php echo $imagethum; ?></a>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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