WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Post Serial Number within a Category

[Resolved] Post Serial Number within a Category

  • Is there a way to number posts when on the category/arhive page? I have attempted using ordered lists, but I’m unsure where to apply them and have used block-level elements to contain titles, content etc.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You may not want to use ordered list because you have less control of how you want the number to appear.

    You could just make your own counter.

    <?php $post_no = 1; ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php echo $post_no; // display as you like ?>
    // display post, etc

    <?php $post_no++; >
    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>

    <?php endif; ?>

    Thank you very much for your help.

    Will this work across pages? That is, will the first post on the next page end up being #1 again?

    Yes, it will

    Ok thanks. I don’t suppose there’s a workaround? (other than showing all posts in the category on the one page – which for me might be actually be the best option…)

    You could do something like this

    $post_no = $counter + $posts_per_page * ($page - 1)

    Of course, you have to somehow get the values for the variables in that formula above

    Thanks alphaoide:)

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Post Serial Number within a Category’ is closed to new replies.