Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Numbered Article List Through Paginated Archive WordPress

  • SOLVED

I have an archive page that lists 14 post titles per page, alphabetically. I've managed to number them sequentially from 1-14 on page 1 but I'd like to keep the numbers going on the next page 2 of pagination, and so on. However, I'm not exactly sure how I can start numbering from 15 on page 2, and so forth for pages 3, 4, 5, etc.

<?php
$page = get_query_var('paged');

$list_number = 1;
?>

<h2><span>Index List // </span>Page <?php echo $page; ?></h2>

<ol>
<?php while (have_posts()) : the_post(); ?>
<li id="post_<?php the_ID(); ?>" <?php post_class(); ?>>
<h3>
<span><?php echo ++ $list_number; ?></span>
<a href="<?php the_permalink(); ?>" title="Click to read '<?php the_title(); ?>'">
<?php the_title(); ?>
</a>
</h3>
</li>
<?php endwhile; wp_reset_postdata(); ?>
</ol>

Answers (4)

2012-10-05

Dbranes answers:

try replace

$list_number = 1;

with

$list_number = 14*($page-1)+1;


Denis Leblanc comments:

Man, you nailed it square in the glasses.

Thanks so much.


Denis Leblanc comments:

Just to expand on that, I made it even more dynamic by fetching the 'posts_per_page' variable so something like this works like a charm:

$list_number = get_option('posts_per_page') * ($page-1) +1;


Dbranes comments:

cool,

ps: if you want to use a check on the $page variable, you can use these one-liners:


$list_number = ($page>0) ? get_option('posts_per_page') * ($page-1) +1:0;

or

$list_number = ($page>0) ? get_option('posts_per_page') * ($page-1) +1:1;


2012-10-05

daas answers:

Hi,
Try this

<?php

$page = get_query_var('paged');

if( $page > 0 )
$list_number = $page*14;

?>



<h2><span>Index List // </span>Page <?php echo $page; ?></h2>



<ol>

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

<li id="post_<?php the_ID(); ?>" <?php post_class(); ?>>

<h3>

<span><?php echo ++ $list_number; ?></span>

<a href="<?php the_permalink(); ?>" title="Click to read '<?php the_title(); ?>'">

<?php the_title(); ?>

</a>

</h3>

</li>

<?php endwhile; wp_reset_postdata(); ?>

</ol>

2012-10-05

Michael Caputo answers:

How about this:

<?php
$page = get_query_var('paged');
$list_number = 0 + $page;
?>
<h2><span>Index List // </span>Page <?php echo $page; ?></h2>
<ol>
<?php while (have_posts()) : the_post(); $list_number++; ?>
<li id="post_<?php the_ID(); ?>" <?php post_class(); ?>>

<h3>

<span><?php echo $list_number; ?></span>

<a href="<?php the_permalink(); ?>" title="Click to read '<?php the_title(); ?>'">

<?php the_title(); ?>

</a>

</h3>

</li>

<?php endwhile; wp_reset_postdata(); ?>

2012-10-05

Abdelhadi Touil answers:

Hi.
But why you don't just use the default archive loop and a plugin to paginate you archive page as you like? or you can use a function for pagination rathan of plugin if you want.
You can just add this code before the loop:
<?php query_posts($query_string.'&posts_per_page=14'); ?>
and the pagination will work perfectly..
If you want me to give you the full code of the archive page just let me know.
Good luck.