Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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 '13 at 11:01

1 Answer 1

up vote 1 down vote accepted

try yo use the build-in loop counter:

  <a data-slide-index="<?php echo $wp_query->current_post; ?>" href=""><?php echo $imagethum; ?></a>
share|improve this answer
    
Thank you for getting to the point. Works perfectly :) –  Noob Theory May 9 '13 at 15:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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