WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For a post x in a category y, how can the following output be achieved:

  • Post x is the nth out of m posts in the category y.

where m is the total number of posts in the category, and n is the number of the current post (ordered by publishing date).

share|improve this question

Are you using the main query or a custom WP_Query for displaying the posts?

If so :

 $wp_query->found_posts; //Main query
 $wp_query->current_post; // current post index


 $my_wp_query->found_posts; //custom wp_query object - total found posts
 $my_wp_query->current_post; // current post index

So, example

 if( have_posts() ) : while( have_posts() ) : the_post();
      <p>The post <?php the_title(); ?> is <?php echo $wp_query->current_post; ?>th of <?php echo $wp_query->found_posts; ?> in category <?php echo 'your cat here'; ?></p>

 <?php endwhile; endif; ?>
share|improve this answer
Instead of hardcoding the "th", here's how to use the proper ordinal suffix: stackoverflow.com/questions/3109978/… – Geert Feb 1 '12 at 15:37
@Geert +1 - I only give rough examples, but that link will surely come in handy. – Shane Feb 1 '12 at 15:42
It's for a single post page. – Ben Feb 1 '12 at 22:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.