Support » Fixing WordPress » how to Reverse the Post Order in an archive page??

  • Hi,guys.
    I’m using wp 2.7.And I am trying to Reverse the Post Order in an archive page.The theme I use doesn’t include an archive.php file.So i created one.I put
    <?php query_posts($query_string.”&order=DESC”); ?>`
    right before<?php if (have_posts()) : ?>
    but it doesn’t work.why?????

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’d like to have this done, as well. Thanks for asking!


    1) Go to your wordpress directory.
    2) Open the file wp-includes/general-template.php.
    3) Look for the function wp_get_archives. In this function, you will find this code:
    if ( ‘monthly’ == $type ) {
    $query = “SELECT DISTINCT YEAR(post_date) AS ‘year’, MONTH(post_date) AS ‘month’, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit”;

    4) Change the value DESC to ASC and save the template.
    5) Your archives will be displayed in ascending order now.
    6) If you are using yearly archives, please select the appropriate code from the template.


    Shane G.

    I am really inexperienced with wordpress but I modified the cutline themes archive page to show my posts by year, month, and post title in ascending order. When someone clicks on say the Oct 25 link the navigation will show the next post as Oct 29, and the previous post as Oct 24 which is correct. But if someone clicks on the month or year tab, the posts are in descending order. How do I get those to display in ascending order also?

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>			
    	<ul >
    $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date ASC");
    foreach($years as $year) :
    	<h4><li><a href="<?php echo get_year_link($year); ?> "><?php echo $year; ?></a>
    		<?php	$months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND YEAR(post_date) = '".$year."' ORDER BY post_date ASC");
    			foreach($months as $month) :
    			<h4><li><a href="<?php echo get_month_link($year, $month); ?>"><?php echo date( 'F', mktime(0, 0, 0, $month) );?></a>
                              <?php  $theids = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND MONTH(post_date)= '".$month."' AND YEAR(post_date) = '".$year."' ORDER BY post_date ASC");
                          		foreach ($theids as $theid):
                                    <h4 style= font-style:italic;><li><a href="<?php echo $theid->ID; ?>"><?php echo $theid->post_title; ?></a></li></h4>
    				endforeach; ?>
                             <?php endforeach;?>
    <?php endforeach; ?>

    Thank you for any help. I did try Shanes suggestion and modified the general-template.php file but it didn’t change anything.


    Yes, I too have this need – I’m writing an 80’s blog and part of it is my diary for 1986 – the only year I have ever kept a diary. I want to show my diary posts starting with the earliest first for this section. I’ve created categories, Jan 86, Feb 86 etc but the posts are always in descending order. Since i’ve been writing july’s entries, i’ve been setting the published on date to the actual date in 1986 – even with Shane’s changes to wp-includes/general-template.php i still (like kittywake) get my posts showing up in descending order. Help!

    Hi, I have found out some more info on this topic – And I have managed to get my diary posts to show in ascending order (result!) – my theme has a file archive.php which I have edited, in accordance with the advice given in topic 197156, to get the desired result.

    You should never be editting core WordPress files to achieve something so simple.

    What do you want to do, simply reverse the display order? Oldest first right?…

    I’m sure i can make something that does not require any core edits, which should only ever be a last resort.

    Heya my sweet cosmicjellybaby

    I’m so very happy you posted the info it worked wonderfully.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘how to Reverse the Post Order in an archive page??’ is closed to new replies.