Adding numbers to post titles in WordPress

In the WordPress support forum (very serious neener neener neener ;-P ) I had seen a request to add numbers to each post title. Giving it some thought and testing here is one way it can be done.

In the index.php file for your theme, before the loop (I put it right after get_header line) add the following code:

<?php if ( $paged < 2 ) {
$my_paged = 0;
} else {
$my_paged = ($paged - 1) * get_option('posts_per_page');
}
$count = 1;
?>

Now inside the loop in the same file put this php code where ever you want the number to appear.

<?php echo $my_paged + $count . ". "; ?>

A good place is right after the <h2> in the default theme, so this line

<h2><a href="<?php the_pemalink() ?>...

becomes

<h2><?php echo $my_paged + $count . ". "; ?><a href="<?php the_pemalink() ?> ...

The count variable needs to be incremented for each post. Before the end of the loop put this line in

<?php $count = $count + 1; ?>

On the default theme this should go right above the <?php endwhile; ?>. This will produce a number with a period and a space before the title.

Since it is before the <a> tag it will not be part of the link to the post.