Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8852609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:26:38+00:00 2026-06-14T13:26:38+00:00

I actually have a PHP loop where I’m giving to each result a number,

  • 0

I actually have a PHP loop where I’m giving to each result a number, starting from 1 and following up in ascending order. The output is as follows:

1) article C
2) article B
3) article A

…but I’d like to reverse the list number, so I get something like:

3) article C (article’s order won’t change, they are descending, by date)
2) article B
1) article A

Here’s my current loop:

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

    <div>
        <span class="count"><?php echo $counter; ?></span>
        <?php the_title(); ?>
    </div>

<?php
$counter++;
   endwhile;
endif;
?>

Is there an easy way to do this?
Many thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:26:39+00:00Added an answer on June 14, 2026 at 1:26 pm

    The WP_Query object has a variable holding the number of posts:

    $query->post_count
    

    So your code can become:

    <?php
    if (have_posts()) :
       global $wp_query;
       $counter = $wp_query->post_count;
       while (have_posts()) :
          the_post(); ?>
    
        <div>
            <span class="count"><?php echo $counter; ?></span>
            <?php the_title(); ?>
        </div>
    
    <?php
          --$counter;
       endwhile;
    endif;
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML output from an API <?xml version='1.0' encoding='UTF-8'?> <Response> <ReturnRow
I have following PHP loop + SQL Update query. for ($i=0;$i<count($_POST['id']);$i++) { if(!isset($_POST['live'][$i])){ $_POST['live'][$i]
I have inherited an big existing PHP application (website actually) that runs on Apache.
1st I have to say I know nothing bout php. I was actually doing
Actually I have to take the sequence number in $Revisions field.
I have a PHP script that works by calling items from a database based
I have a simple javascript loop on my php page that just adds 1
Basically I have a foreach loop bringing in data from an array of products
I have a piece of php code that reads values from a database resultset,
I actually have right now two questions: 1) What font faces are preferred for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.