Forums Forums Search & Filter Pro Get the index of current post in search query

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #109913

    Hi,
    for styling reasons, I need to create an index number related to the search query’s current post.
    How can I associate this numer as an $index var to the current post’s styling on the archive page?
    Just a code sample may be ok.

    Anonymous
    #109929

    Sample of the query I’m using in other templates and that must be reused for styling the sf_query resuslt:

    `<?php while ( $wp_query->have_posts() ) : $wp_query->the_post();
    $index = $wp_query->current_post + 1; ?>
    section:nth-child(<?php echo $index; ?>) > .category {
    background:url(‘<?php the_post_thumbnail_url(‘large’); ?>’);
    box-shadow: inset 0px 0px 400px 110px rgba(0, 0, 0, .7);
    }
    <?php endwhile; ?>

    Anonymous
    #109934
     while ( $sf_current_query->have_posts() ) : $sf_current_query->the_post();
      $index = $sf_current_query->current_post + 1; ?>
      section:nth-child(<?php echo $index; ?>) > .category {
      background:url('<?php the_post_thumbnail_url('large'); ?>');
      box-shadow: inset 0px 0px 400px 110px rgba(0, 0, 0, .7);
    }
    <?php endwhile;
    Anonymous
    #109936

    solved with that last code sample 🙂

    Anonymous
    #109938

    OH NO,
    didn’t solve anything… please let me know…

    Trevor
    #109977

    I need to understand a bit better.

    Are you simply wanting to add 1 to a class in the first post, 2 to the next post, etc.

    all you would do is set a custom variable before the ‘while’ starts to = 1, e.g.:

    $my_post_index = 1;

    And echo that in the code. Just before the endwhile, you increment this by one, e.g.:

    $my_post_index++;

    Is this what you wanted to do?

Viewing 6 posts - 1 through 6 (of 6 total)