plugins - Display posts by alphabetical order

admin2025-01-07  4

I just purchased a WordPress theme. I’m trying to sort post on one category into an alphabetical listing (glossary type of listing).

Example : /

There are using a WordPress theme, I just don’t know how to create that.

I have tried several plugins (like A-Z Listing and others) but it doesn't look good at all.

Could you please help me please ? Do you know a plugin or a way to create this please ?

thank you

I just purchased a WordPress theme. I’m trying to sort post on one category into an alphabetical listing (glossary type of listing).

Example : https://www.udiscovermusic.com/browse-artists/

There are using a WordPress theme, I just don’t know how to create that.

I have tried several plugins (like A-Z Listing and others) but it doesn't look good at all.

Could you please help me please ? Do you know a plugin or a way to create this please ?

thank you

Share Improve this question asked Aug 30, 2021 at 17:19 MarketboyMarketboy 1 2
  • Are you dealing with posts or custom post types? For custom post types, you might need to implement a different logic than for posts. – Badan Commented Aug 30, 2021 at 22:29
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Bot Commented Aug 31, 2021 at 9:16
Add a comment  | 

1 Answer 1

Reset to default 0

You can change the sort order on a category archive page to show posts by title (A-Z) by adding this code to your child theme's functions.php:

/* Sort posts by title for a specific category */
function change_category_order( $query ) {
    //Sort all posts from category with id=3 by title
    if($query->is_category('3') && $query->is_main_query()){
        $query->query_vars['orderby'] = 'name';
        $query->query_vars['order'] = 'DESC';
    } 
}
add_action( 'pre_get_posts', 'change_category_order' );

You need to replace "3" with the correct category id. You can find out the category id by heading to dashboard => post => categories and hover over the category you want to adjust the sort order.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736259569a599.html

最新回复(0)