I have a section in my site where I display the 10 most popular posts. Now, I want to display a number, from 1 to 10, besides each post. Like this:

Top 10 posts

  1. post a
  2. post b
  3. post c

and so on...

I implemented a counter inside the while loop. I initialized the counter at 0 $counter = 0; and then incremented it by one <?php echo ++$counter; ?>

My concern is, due to my site receiving thousands of visits a day, I want to know if this method will consume my site's resources considerably. Is there a better way to do this? Maybe to implement some sort of caching?

What advice can you give me?

1 Answer 1


Another solution would be to use an ordered list.

$my_query = new WP_Query($args);
if ( $my_query->have_posts() ) :
    echo '<ol style="list-style:decimal">';
    while( $my_query->have_posts() ) : $my_query->the_post();
      echo '<li><a href="' . get_permalink( get_the_ID() ) . '">' . get_the_title() . '</a></li>';
    echo '</ol>';
  • +1 from me. I always write php and forgot that html exists :)
    – gmazzap
    Sep 7, 2013 at 8:43
  • I tried your solution, however, the numbers are not displaying.
    – Gixty
    Sep 7, 2013 at 8:44
  • @Gixty is a css problem, I think.
    – gmazzap
    Sep 7, 2013 at 8:46
  • @Gixty added style="list-style:decimal" to force number showing
    – gmazzap
    Sep 7, 2013 at 8:49
  • @Horttcore: Thank you!! yes it is, i found this: stackoverflow.com/questions/4643913/…
    – Gixty
    Sep 7, 2013 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.