Search code examples
wordpressposts

Auto numbering Wordpress Taxonomy Post Type Category Posts with 0 ahead of it


I want to generate automatically Wordpress taxonomy posts number next to the content like this this picture. How Can i do it and put 0 for the first 9 posts?


Solution

  • Found a crazy and simple solution.Here is the code with loop
    <?php $counts = 1 ; ?> <?php $query = new WP_Query( array('post_type' => 'benefits', 'posts_per_page' => 1000 ) ); while ( $query->have_posts() ) : $query->the_post(); ?> <div class=""> <?php if($counts < = 9){ echo '0'.$counts; }else{ echo $counts; } ?> </div> <?php $counts++; endwhile; ?>