• Resolved lozboz

    (@lozboz)


    Hi, I’m using Freshy theme by Jide. 809 on my photo 365 project blog

    I would like to change the ‘newest first’ sort order for the month archive listings.
    I know that by default the theme post display order is set to descending order and we can change it by adding below mentioned code in index.php file of current active theme. However, this changes all display post orders.

    Can it be achieved selectively?

    Thanks

    Laurie

Viewing 5 replies - 1 through 5 (of 5 total)
  • I know that by default the theme post display order is set to descending order and we can change it by adding below mentioned code in index.php file of current active theme.

    Did you forget something? ?? … *hint* the code you mentioned.

    To answer the question though, yes you can change query parameters selectively in different situations..

    My question now is, does your theme have an archive.php file, and how capable are you with code, do you need an example or just some guidance on what functions to call etc… ?

    Thread Starter lozboz

    (@lozboz)

    Hi,

    Thanks for the quick response.

    Yes, I missed that the code I was copying was an image. I meant to quote <?php query_posts(‘order=ASC’); ?>

    Yes, my theme has an archives.php and I can edit it.

    I am new to this code but quite capable in other languages, so I’m happy to learn! I could certainly do with some assistance in identifying functions etc.

    Thanks

    Laurie

    Does your theme have an archive.php file? If so, make your changes to that template file. If not, make a copy of index.php and name the new copy “archive.php. Then make your changes.

    If you want to retain pagination, you might also want to extend the query to:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'order' => 'ASC',
    	'paged' => $paged
    );
    query_posts($args);
    ?>

    Alternatively, function..

    // 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;
    }

    in the theme’s functions.php … ??

    Thread Starter lozboz

    (@lozboz)

    Thank you very much, it worked a treat!

    Cheers

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sort Posts in ascending order for Archive listing only’ is closed to new replies.