use php to assign numbers to paged wordpress posts

Hi, I'm trying to work out the code to add an increasing number in front of each wordpress post as they are displayed over several pages. I was hoping to show 10 posts per page.

Page 1 show 1 - 10

page 2 shows 11 - 20 and so on

I've got so far. Created a variable which increases in each iteration of The Loop. eg.

<?php $counter = 1; ?>

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?>

... skipping some code ...

<h1>#<?php echo $counter; ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?> blurb"><?php the_title(); ?></a></h1>

<?php $counter++; ?>

Works fine if I have all the posts on one page but as soon as I split it over two pages the second page starts again with the first post showing 1 - not 11.

I believe WordPress keeps the page number in a variable called $paged, and I think I need to global $paged and add ($paged * num_per_page) to the counter but being a php dunce it's all a bit beyond me.

I'm hoping someone can give me the exact code I need to use. Probably only a two minute job if you know what you're doing.


Taidot: PHP

Näytä lisää: wordpress assign numbers posts, wordpress assign numbers, wordpress post a job, it works global, assign numbers wordpress posts, code php assign number, assign page php, paged wordpress, paged count wordpress, wordpress asign post number, asign post page wordpress, wordpress php assign post, assign project number, assign post page wordpress, Use, php to c, h1>, h1, bookmark php, use php, counter php, wordpress show post page, php global variable, iteration, wordpress global post

Tietoa työnantajasta:
( 13 arvostelua ) Guildford, United Kingdom

Projektin tunnus: #413956

Myönnetty käyttäjälle:


Hello! I can do it for You for only $30. It will take me no longer than 1-2 hours from now. IF You choose me I will do my best to do it as soon as possible. I can start immidiately. best regards Birdwatcher

30 $ USD 0 päivässä
(62 arvostelua)

3 freelanceria on tarjonnut keskimäärin 30 $ tähän työhön


hello, i can help you getting this out. thanks

30 $ USD 1 päivässä
(34 arvostelua)

Hi Try changing this line to this hope this helps Alex

30 $ USD 0 päivässä
(45 arvostelua)