• Hey there,

    I’m building a WordPress site for a client with a unique page structure. Basically, when a user loads the site, the site loads at the bottom of the page. From there, the user will scroll up to view content. Basically, the header is actually the footer.

    The problem that I’m having now is that I need the newest post to display at the bottom of the page and older posts displaying above that in chronological order. Something like this:

    (Footer)
    Post 5
    Post 6
    Post 7
    Post 8
    Post 9
    (Header) [user’s browser window starts here, then they scroll up]

    However, when I set up the posts in ASC order, the first page will always show the the original first 5 posts, like this:

    (Footer)
    Post 1
    Post 2
    Post 3
    Post 4
    Post 5
    (Header)

    So my question is, can I leave the loop posts as DESC, meaning that the 5 newest posts will always be displayed on the index page, but at the same time, take those 5 posts that are being displayed and reverse their order? So something like this:

    Index Page:
    (Footer)
    Post 8
    Post 9
    Post 10
    Post 11
    Post 12
    (Header)

    Page 2:
    (Footer)
    Post 3
    Post 4
    Post 5
    Post 6
    Post 7
    (Header)

    Page 3:
    (Footer)
    Post 1
    Post 2
    (Header)

    Hopefully this makes sense, at least what I’m trying to do.

Viewing 1 replies (of 1 total)
  • You can reverse the order of the posts on a page using array_reverse(), like this:

    $wp_query->posts = array_reverse($wp_query->posts);

    Use this just before the while (have_posts()) loop.

Viewing 1 replies (of 1 total)
  • The topic ‘Advanced Post Ordering’ is closed to new replies.