WordPress.org

Support

Support » How-To and Troubleshooting » Post reverse order with most recent posts on homepage

Post reverse order with most recent posts on homepage

  • Hello everyone! I want my posts to show up in reverse order, so that the oldest ones are at the top and the newest ones are at the bottom. Why? Because I want it to mimic entries in a diary. I did this without a problem.
    The problem is that I only want 3 entries to show up on the page, and once I write my 4th entry it shows up on the following page. So if you go to my website, you see the 3 oldest entries. I’d like for my posts to be in reverse order, but still to have the homepage show the 3 most recent entries. Can anyone help me with this?

Viewing 15 replies - 1 through 15 (of 16 total)
  • Did you try changing the setting under Admin->Reading->’Blog pages show at most’?

    Or add the ‘posts_per_page=3’ paramete to your query?

    Thanks for your reply. I used the Readin settings to limit the blog to 3 posts on a page. It did limit to 3 posts, but it’s my 3 oldest posts instead of my 3 newest posts.

    Here’s what I have on my index page:

    <?php query_posts($query_string . "&order=ASC"); $recent_posts = wp_get_recent_posts( $args ); ?>
    <?php while ( have_posts() ) : the_post() ?>

    It did the job of ordering my posts in ascending order, but it still shows the 3 oldest posts rather than 3 newest.

    Did you add the part about ‘$recent_posts = wp_get_recent_posts ( $args );’?

    I can’t see enough of the code to tell if that is causing a problem. If you added that, try taking it out. If not, what are the args in $args?

    Yes I did add them, because I saw it somewhere on another forum. Just took it out and it makes no difference. Does wordpress default to showing the page of the oldest posts when sorted by date in ascending order? Really confused by this.

    Yes. ASC order should give you the oldest first.

    Do you have ‘sticky’ posts? Those are independent of the order and will show up first. If you have 3 of them, they will always show up as the first 3 regardless of the order.

    You can override the ‘sticky’ behaviour by adding the ‘caller_get_posts’ argument to the query:

    <?php query_posts($query_string . "&order=ASC&caller_get_posts=1"); ?>

    Hmm, I don’t have sticky posts. I know that the older posts will show up in ASC order, which is what I want. Just can’t figure out how to have the home page to show the 3 latest instead of the 3 oldest. I tried the caller_get_posts like you suggested but still get the same result.

    My bad, I totally missed that you wanted the home page to show the 3 newest and all other pages to show the 3 oldest.

    Please give this a try:

    <?php if (is_front_page()) {
       $order = 'DESC';
    } else {
       $order = 'ASC';
    } ?>
    <?php query_posts($query_string . "&order=$order"); ?>

    Sorry, I don’t think I was very clear on what I’m trying to do. When the user goes to the website, I want them to see the three newest posts from oldest to newest at the bottom. When they click “Older Posts”, they’ll see the three previous posts, also in ascending order. So for example:

    Home page:

    Post from January 1
    Post from January 2
    Post from January 3

    Click “older posts”

    Post from January 4
    Post from January 5
    Post from January 6

    Does that make sense? Thanks a lot for your help, by the way.

    Now I’m confused. You said you wanted the 3 newest posts, yet you showed the 3 oldest. ‘Jan 1’ is older than ‘Jan 2’, etc.

    And, clicking ‘Older posts’ actually shows newer posts.

    Ah, sorry. That’s not at all what I want. Haha. Let me try that again.

    Home Page:

    Post from January 4
    Post from January 5
    Post from January 6

    Click “older posts”

    Post from January 1
    Post from January 2
    Post from January 3

    So all the pages show the posts in ASC order, but the home page will be the 3 most recent rather than 3 oldest.

    I basically just want it to look like a diary. The theme I’m using is made to look like a diary, with each post being an entry. Each page will be 3 diary entries, and the book will by default be opened at the last page so you can see the latest entries. You can flip bag pages to read posts from the past.

    OK – I think I get it. On the Home page, posts are really DESC overall, but ASC within each page. If that is correct, please try this:

    <?php if (is_front_page()) {
       $order = 'DESC';
    } else {
       $order = 'ASC';
    } ?>
    <?php query_posts($query_string . "&order=$order"); ?>
    <?php if (is_front_page()) $wp_query->posts = array_reverse($wp_query->posts); ?>

    Signing off for the night. Will check back tomorrow.

    Let me start off by saying I really appreciate your help. It’s still not giving me what I want, though. I want posts to be in ascending order, but I just want the home page to show the latest posts (also in ascending order). I can’t figure out how to get my most recent posts on the home page without putting them in descending order.

    The code I posted was tested to give what you showed in your diagram.

    You MUST do the home page query in DESC order to get the most recent posts first. Then, the array_reverse presents them in ASC order.

    That should match the diagram you last showed.

    What are you seeing?

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Post reverse order with most recent posts on homepage’ is closed to new replies.