Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What is the best way to display the appearance number of a post in a query?

For example, if a post is the first listed print #1. If it is third, print #3.

Any direction is appreciated!

share|improve this question
1  
start a counter before The Loop, display the value of the counter in the loop. –  Nicholas Pickering Feb 21 '13 at 23:12
add comment

1 Answer 1

up vote 4 down vote accepted
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) :
    $the_query->the_post();
    echo('#' . $the_query->current_post + 1); // $the_query->current_post has the index
endwhile;
share|improve this answer
add comment

Your Answer

 
discard

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.