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,
The WP_Query object has a variable holding the number of posts:
So your code can become:
If there is a function returning the posts count, e.g.
count_posts()
(just guessing), use it this way:If this is a wordpress based site/page and the function have posts relates to the wordpress function:
You might be better off with something like query_posts:
http://codex.wordpress.org/Function_Reference/query_posts
Which gives you much better control over display of the posts?
Edit:
Or alternatively if you use this:
You can use this in tandem with the other answers by reversing your counter ($counter–;)
That should do the trick
http://codex.wordpress.org/Function_Reference/wp_count_posts