Forums › Forums › Search & Filter Pro › Get the index of current post in search query
Tagged: index number, results
- This topic has 5 replies, 2 voices, and was last updated 7 years, 6 months ago by Trevor.
-
Anonymous(Private) May 19, 2017 at 11:21 am #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(Private) May 19, 2017 at 11:29 am #109934while ( $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;
Trevor(Private) May 19, 2017 at 3:27 pm #109977I 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?
-
AuthorPosts