1

I am having a hard time reversing this loop.

Atm, the loop is showing the newest posts first, because these are added on top of the others in an array i guess, whereas i want it to show the oldest first.

So my question is, how to make the oldest posts show first, and the newest show at the end?

This is the code which shows the newest posts first, in a while loop:

while($portfolio->have_posts())
{
    $portfolio->the_post();
    $post = get_post();
    $output .= '<a class="w-portfolio-item-anchor" href="javascript:void(0);" data-id="'.$post->ID.'">'
}
return $output;

Regards, Patrick

iatboy
  • 1,295
  • 1
  • 12
  • 19
Patrick
  • 166
  • 2
  • 14

1 Answers1

2

To reverse this, add this to your theme somewhere, just before your loop:

query_posts($query_string . "&order=ASC");

Or find where it is currently being queried for and ensure that &order=ASC is used.

Or, as @ɴ-ᴀ-ᴛ-ʜ mentioned in a comment, change this:

$output .= '<a class="w-portfolio-item-anchor" href="javascript:void(0);" data-id="'.$post->ID.'">'

To this:

$output = '<a class="w-portfolio-item-anchor" href="javascript:void(0);" data-id="'.$post->ID.'">' . $output;
Scott
  • 3,736
  • 2
  • 26
  • 44
  • 1
    Awesome, thanks for the update with the comment from N A T H. The answer which worked for was the one by @ɴ ᴀ ᴛ ʜ . – Patrick Oct 28 '14 at 14:37