WordPress.org

Ready to get started?Download WordPress

Forums

Archive oldest to newest post (4 posts)

  1. wilmcgil
    Member
    Posted 1 year ago #

    I am looking for a way to change the order of our Monthly Archives from the oldest post first to the newest.

    The url that shows the monthly Archive is http://wordpress-site.com/2012/06.

    I have looked at archive.php, but there is no wp query to modify.

    Sorry if this is a dumb question, but where can I specify the order of the posts?

    tx

    Wil

  2. Tom Combs
    Member
    Posted 1 year ago #

    Hi,

    I would do it by creating a custom query.

    On your archive.php page, replace this:

    <?php
    	/* Since we called the_post() above, we need to
    	 * rewind the loop back to the beginning that way
    	 * we can run the loop properly, in full.
    	 */
    	rewind_posts();
    
    	/* Run the loop for the archives page to output the posts.
    	 * If you want to overload this in a child theme then include a file
    	 * called loop-archive.php and that will be used instead.
    	 */
    	 get_template_part( 'loop', 'archive' );
    ?>
    

    With this:

    <?php
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $args = array( 'paged' => $paged, 'posts_per_page' => 10, 'orderby' => ASC );
    // The Query
    query_posts( $args );
    // The Loop
    while ( have_posts() ) : the_post(); ?>
    
  3. wilmcgil
    Member
    Posted 1 year ago #

    Hey thanks for the response - The only thing I see on the Archive.php is this...

    <?php $i = 1; ?>
    <?php if (have_posts()) : ?>

    and

    <?php $post = $posts[0]; /* Hack. Set $post so that the_date() works. */ ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ($i == 1) : ?>

    I tried your query, but it didn't work.

    tx

    Wil

  4. Tom Combs
    Member
    Posted 1 year ago #

    If you are using a premium template, you should contact the developer.

    The code you have above isn't the standard loop query for the archive.php page.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.