WordPress.org

Ready to get started?Download WordPress

Forums

how to Reverse the Post Order in an archive page?? (8 posts)

  1. scutdk
    Member
    Posted 5 years ago #

    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?????

  2. cocteauboy
    Member
    Posted 5 years ago #

    I'd like to have this done, as well. Thanks for asking!

  3. Shane G
    Member
    Posted 5 years ago #

    Hi,

    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.

    Thanks,

    Shane G.

  4. kittywake
    Member
    Posted 4 years ago #

    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 >
    <?php
    /**/
    $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>
                    <ul>
    		<?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>
    
    		      <ul>
                              <?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="http://www.kittywake.us/?p=<?php echo $theid->ID; ?>"><?php echo $theid->post_title; ?></a></li></h4>
    
    			<?php
    				endforeach; ?>
    
    			</ul>	          
    
    	                </li></h4>
    
                             <?php endforeach;?>
                  </ul>
    
            </li></h4>
    <?php endforeach; ?>
           </ul>
    
    			</div>

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

    Sue

  5. cosmicjellybaby
    Member
    Posted 4 years ago #

    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!

  6. cosmicjellybaby
    Member
    Posted 4 years ago #

    Hi, I have found out some more info on this topic - http://wordpress.org/support/topic/197156 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.

  7. Mark / t31os
    Moderator
    Posted 4 years ago #

    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.

  8. Franklyn Monk
    Member
    Posted 4 years ago #

    Heya my sweet cosmicjellybaby

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.