• Hi all,

    Can someone help me reverse the order of my blog posts, i want them to show the oldest first and newest last, my code is below, if anyone can adjust it to do that, I would be so grateful.

    Thanks all!!

    <ul>
          <?php while ( have_posts() ) : the_post(); ?>
    
    <li> <a>" title="<?php the_title(); ?>">
             <strong><?php the_time('j M Y');?>:</strong> <?php the_title(); ?>
            </a> </p>
          <?php endwhile; // end of the loop. ?>
          </li>
    </ul>
Viewing 5 replies - 1 through 5 (of 5 total)
  • <?php
    $asc_order = new WP_Query( array( 'order' => 'ASC') );
    
    if ( $asc_order->have_posts() ) : ?>
    <ul>
          <?php while ( $asc_order->have_posts() ) : $asc_order->the_post(); ?>
    <li> <a>">
             <strong><?php the_time('j M Y');?>:</strong> <?php the_title(); ?>
            </a> </p>
          </li>
          <?php endwhile; // end of the loop. ?>
    </ul>
    
    <?php
    endif;
    /* Restore original Post Data */
    wp_reset_postdata();
    ?>

    For more info, here you go:
    https://codex.www.ads-software.com/Class_Reference/WP_Query

    By the way, your html has some mistakes. I didn’t fix them, only added PHP codes you need. I hope I could give the idea

    Thread Starter gavjayhoffman

    (@gavjayhoffman)

    That is great thank you but originally (didnt include it in my code sorry) i had it pulling in from a certain category using:

    <?php query_posts('cat=37');?>

    Could you implement that for me?

    There is a line in my code like this:

    $asc_order = new WP_Query( array( 'order' => 'ASC') );

    Replace it with

    $asc_order = new WP_Query( array( 'order' => 'ASC', 'cat=37' ) );

    Thread Starter gavjayhoffman

    (@gavjayhoffman)

    Thanks man, that’s what I tried and it didn’t want to work?

    Thread Starter gavjayhoffman

    (@gavjayhoffman)

    Ahh, got it, it was this:

    $asc_order = new WP_Query( array( 'order' => 'ASC', 'cat' => '37' ) );

    Thanks again mate, a MASSIVE help

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Reverse order of posts’ is closed to new replies.