Reverse the way of function output

2019-08-10 08:33发布

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

标签: php wordpress
1条回答
Deceive 欺骗
2楼-- · 2019-08-10 09:01

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;
查看更多
登录 后发表回答