0

In wordpress I'm trying to show the list of categories in a page. I'm simply using the function "wp_list_categories" to show the categories and it actually works pretty well however, I would like to have that in an alphabetically ordered list like under "A" (all the categories that starts with A). What can I do to achieve that. I don't have any php knowledge just HTML,CSS, Javascript. Any help in this regard would be much appreciated. Thanks in Advance!

Code I'm using :

wp_list_categories(array(
    'style' => 'none',
    ))

ref: Alphabetically ordered category list

1 Answer 1

1

WordPress is a pretty well documented CMS which means at you can probably google the function name and find the answer based on parameters. If we look at the documentation of wp_list_categories() we see it has both an order and orderby which we can pass in. So, to order the categories in an alpha-numeric list we can say:

wp_list_categories( array(
    'style'     => 'none',
    'orderby'   => 'name',
    'order'     => 'ASC',
) );

You can also use DESC to change reverse order.

5
  • I'm already getting that result by default, my categories are appearing in alphabetical order but i want to put them in alphabetical sections like the categories starts with As would appear under A and Bs under "B". Thank you for responding!
    – John D
    Commented Apr 20, 2017 at 17:31
  • @JohnD I'm still not sure I understand what you mean, this should "group" all categories that start with "A" at the top and "Z" at the bottom of the list. What is happening in your list currently that is different than what you want to happen? Feel free to edit your question and add in more detail as there's more space than here in the comments for examples and explainations.
    – Howdy_McGee
    Commented Apr 20, 2017 at 17:32
  • Sorry I might be not explaning it right. Please have a look at the ref link in my post. It has an example for the same.
    – John D
    Commented Apr 20, 2017 at 17:38
  • @JohnD it looks like that question contains your answer, you just need to make the changes detailed in the accepted answer to the code provided in the question.
    – Milo
    Commented Apr 20, 2017 at 17:49
  • @JohnD you can easily do that. Use add_filter('wp_list_categories', 'wp_list_categories',10,2); function wp_list_categories($args) { } now overwrite your list categories as you expected. I am giving you an example in the answer. Commented Apr 20, 2017 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.