Display post count on archive page in reverse order

I'm displaying some posts and I want each of them to display a post number. The first post being number 1, the most

I'm displaying some posts and I want each of them to display a post number. The first post being number 1, the most recent post being 10 (let's say there's 10 posts.)

I'm currently using

<?php echo $wp_query->current_post + 1?>

Which works except the newest post is 1 and the oldest post is 10. How do I reverse this?

I'm displaying some posts and I want each of them to display a post number. The first post being number 1, the most recent post being 10 (let's say there's 10 posts.)

I'm currently using

<?php echo $wp_query->current_post + 1?>

Which works except the newest post is 1 and the oldest post is 10. How do I reverse this?

Share Improve this question asked Apr 12, 2019 at 16:10 Garrett ScafaniGarrett Scafani 731 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can give a try to this within a loop

<?php 
      echo $wp_query->found_posts - $wp_query->current_post ;
?>

$wp_query->found_posts gives the total number of posts found matching the current query parameters.

So the if there are 20 posts, result for each post should look like this

For 1st post it will display 20, i.e. 20-0=20
For 2nd post it will display 19, i.e. 20-1=19, ...
...
...
For 12th post it will display 9, i.e. 20-11=9, and
For 20th post it will display 1, i.e. 20-19=1,

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745595570a4635090.html

相关推荐

  • Display post count on archive page in reverse order

    I'm displaying some posts and I want each of them to display a post number. The first post being number 1, the most

    21小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信