Archived topic
Alphabetizing Posts in Categories
1 reply · Started by K Bell on February 2, 2021
Hello,
My site is a dictionary, with a category for each letter.
The plugin I am using to alphabetize posts has been deprecated.
WordPress provides these directions to change the categories.php file to achieve the same effect. However, I cannot find the Category Template within the theme editor.
How would I make all categories sort alphabetically within this theme?
Thank you,
Kenton
Hi,
I'm not sure I fully understand what you mean.
To clarify: Do you want the post lists to be sorted alphabetically by title?
If so, from the same page you've linked, you can use pre_get_posts.
Example: Sorting archives using title in ascending order.
function modify_query_order( $query ) {
if ( $query->is_archive() && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'modify_query_order' );
Here's how to add PHP: https://docs.generatepress.com/article/adding-php/