WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Post Serial Number within a Category (7 posts)

  1. Sean
    Member
    Posted 8 years ago #

    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.

  2. Joshua Sigar
    Member
    Posted 8 years ago #

    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; ?>

  3. Sean
    Member
    Posted 8 years ago #

    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?

  4. eridan
    Member
    Posted 8 years ago #

    Yes, it will

  5. Sean
    Member
    Posted 8 years ago #

    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...)

  6. Joshua Sigar
    Member
    Posted 8 years ago #

    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

  7. Sean
    Member
    Posted 8 years ago #

    Thanks alphaoide:)

Topic Closed

This topic has been closed to new replies.

About this Topic