Took me a while to get this working. Requires a hosted version of WordPress; I don’t think this sort of thing is possible if you’re using a free WordPress.
- Edit the main wordpress query to set ascending order on category pages
- Go to Appearance > Editor and open functions.php (“Theme Functions”)
- Add the following code after the <?php
- Click Update file
- View a category page – your posts should now be in ascending order
- Check the home page – the posts should still be in descending order
- On the category page you probably have an “older posts” button at the bottom of the page, which should really now read “newer posts”. An easy way to avoid this problem is to use infinite scrolling
- Go to Settings > Reading
- Check “scroll infinitely”
Here’s the code you need
add_action( 'pre_get_posts', 'my_query' );
function my_query( $wp_query ){
if(is_admin() || !$wp_query->is_main_query()){
return;
}
if ( is_category() ){
$wp_query->set( 'order', 'ASC' );
}
}
Leave a Reply