WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Incrementing number within WP_Query?

[Resolved] Incrementing number within WP_Query?

  • Hey everybody,

    I’m setting up a photo gallery for my WordPress site, and for navigation purposes I need to increment a link’s data-slide-index value by 1 for every post.

    So far nothing I’ve tried as worked, and I suspect it’s because I’m using multiple loops on the page via WP_Query.

    Here’s my loop. Can anybody tell me what I need to do here?

    <?php $photo_thumbs = new WP_Query('post_type=photo-gallery&posts_per_page=100&order=DESC');
    while ($photo_thumbs->have_posts()) : $photo_thumbs->the_post(); ?>
    <div class="thumb">
    <span class="mid"><a data-slide-index="VALUE TO BE INCREMENTED" href=""><?php the_post_thumbnail('photos_thumbnails'); ?></a></span>
    </div>
    <?php
    endwhile;
    wp_reset_postdata();
    wp_reset_query();
    ?>

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi
    Forum Moderator

    @esmi

    <?php $photo_thumbs = new WP_Query('post_type=photo-gallery&posts_per_page=100&order=DESC');
    $c = 0;
    while ($photo_thumbs->have_posts()) : $photo_thumbs->the_post(); $c++; ?>
    <div class="thumb">
    <span class="mid"><a data-slide-index="<?php echo $c;?>" href=""><?php the_post_thumbnail('photos_thumbnails'); ?></a></span>
    </div>
    <?php
    endwhile;
    wp_reset_postdata();
    wp_reset_query();
    ?>
    yakbrother
    Member

    @yakbrother

    Edit: Nevermind, already answered…

    esmi
    Forum Moderator

    @esmi

    Aww… I was going to call “snap!”. 😉

    Thanks! That’s exactly what I needed!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Incrementing number within WP_Query?’ is closed to new replies.