• Resolved Frances Allen

    (@frances-allen)


    I have created a blog archives page. I would like the months to remain in descending order (as with the current blog), but the posts within each archived month to be ascending, ie chronological. I would also like people to view an archived month as one continuous file, rather than keep clicking on older posts.

    I know these questions have been dealt with before, but the solutions require more coding expertise than I have! Could some kind soul tell me what code I need to insert, in what files and where in the file.

    I’m using the chunk theme and have set up a chunk child theme. One day I will get round to learning about php etc – honest.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi there, you can add a function in your child theme to reverse the default order of archives display so that the older posts are shown first, instead of the newer ones.

    If you put this into a blank plain-text file called functions.php in your child theme it should do the trick – it works on my test site.

    <?php
    
    // Runs before the posts are fetched
    add_filter( 'pre_get_posts' , 'my_change_order' );
    // Function accepting current query
    function my_change_order( $query ) {
    	// Check if the query is for an archive
    	if($query->is_archive)
    		// Query was for archive, then set order
    		$query->set( 'order' , 'asc' );
    	// Return the query (else there's no more query, oops!)
    	return $query;
    }
    
    ?>

    This function was provided by a user here.

    I’ll answer your other question separately.

    I would also like people to view an archived month as one continuous file, rather than keep clicking on older posts.

    I did some searching and found this function to remove pagination. I adapted it to use is_date() (Codex), so pagination is removed only on date-based archives:

    function no_nopaging($query) {
    	if (is_date()) {
    	$query->set('nopaging', 1);
    	}
    }
    
    add_action('parse_query', 'no_nopaging');

    Put this function in the functions.php file you made earlier, and be sure to add it before the closing PHP tag: ?>

    Keep in mind that if any month has a lot of posts, or posts with a lot of content like images, these archives pages may take a long time to load.

    Let me know how it goes!

    Thread Starter Frances Allen

    (@frances-allen)

    Kathryn
    Thank you SO much. Both functions worked perfectly.
    I do appreciate the time you spent replying, particykarly over the holiday season.
    I hope the two answers help others too.

    You’re welcome – glad those functions did the trick.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Make archive posts ascending and without page breaks’ is closed to new replies.