Give each posts in a loop a number in sequence

As this is a presentational thing, I’d be inclined to use CSS (there are of course ways of doing it in PHP, and others may disagree.)

You’d make use of the counter-reset and counter-increment properties.

CSS counters can be applied to any element, not just ordered-lists (<ol></ol>) and added using pseudo-elements and you can control the starting number and how it is incremented (counters can even run in reverse.)

They have very high browser support (essentially IE8 and above, and anything else.)

Here’s some code for the twentyfourteen theme:

.home .site-content {
    counter-reset: posts -1;
}

.home article {
    counter-increment: posts;
}

.home .entry-title:before {
    content: counter(posts) '. ';
}

Note:

  • Not compatible with pagination, as list will still start at 0 on subsequent pages
  • The counter has to have a unique name – “posts”
  • The counter is incremented for each <article> tag
  • You want the first item to be 0, so we have to start at minus 1, because the first article will increment it by 1
  • Only tested in latest Chrome and Firefox, but 97% global browser support as mentioned above