Support » Fixing WordPress » counter to count backwards for php

  • Resolved gbaka

    (@gbaka)


    I’m trying to figure out how to make my counter to count backwards in the while loop for my post so when i echo it get 3 2 1 order, in order of post creation instead of 1 2 3 which isn’t in post order.

Viewing 9 replies - 1 through 9 (of 9 total)
  • gbaka

    (@gbaka)

    so anyone?

    gbaka

    (@gbaka)

    anyone?

    Moderator James Huff

    (@macmanx)

    Can you share a link to your blog? What theme are you using? Is the counter a plugin or hard-coded?

    gbaka

    (@gbaka)

    its php code as in $counter++ and I’m echoing it in the while post loop to get numbers but its going 1 2 3 4 order and i want it in the reverse order so the first post will remain as 1 instead of changing to a 2 so in short i want it to go 4 3 2 1…

    Moderator James Huff

    (@macmanx)

    Thanks, we also need to know what theme you’re using. And, if you share a link to your blog, it would help quite a bit.

    gbaka

    (@gbaka)

    I’m using a custom theme and this is basically the code

    <?php $titlecount = 0; ?>
    
    <?php while (have_posts()) : the_post(); ?>
    <?php $titlecount++; ?>
    
    <?php echo $titlecount; ?>
    
    <?php endwhile; ?>

    this is in the archive.php

    gbaka

    (@gbaka)

    anyone?

    jrav001

    (@jrav001)

    Loop through all the posts (without displaying them) to count the total number to display.

    Now that you have a total for $titlecount, run the loop again, but this time, decrease the count using $titlecount--

    gbaka

    (@gbaka)

    thank you that worked like a charm!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘counter to count backwards for php’ is closed to new replies.