Create a counter in wordpress for each post

188 Views Asked by At

I am using wordpress and want to add a counter to each post that increases and echos out the increased number.

here is what I am doing so far which seems ridiculous. There has to be a better way haha.

$my_count=0;
$my_count++;

<div class="wow fadeInUp" data-wow-offset="100" data-wow-delay=
<?php if( $my_count == 1) { ?>"0s"<?php } ?>
<?php if( $my_count == 2) { ?>"0.3s"<?php } ?>
<?php if( $my_count == 3) { ?>"0.6s"<?php } ?>
>

Let me know if that makes any sense, but basically I am trying to increase the delay for each post without writing it out like this. (having 100 posts could be unreal as you can imagine : /

Thanks for your time in helping me out!

1

There are 1 best solutions below

1
On BEST ANSWER

I assume this is in your while( have_posts() ) loop? If so, use that to your advantage:

    $my_count=0;
    while( have_posts() ): the_post();
?>
    <div class="wow fadeInUp" data-wow-offset="100" data-wow-delay="<?php print ( $my_count * 0.3 ); ?>s">
      ...
    </div>
<?php
    $my_count++;
    endwhile;