Skip to content

WordPress: Change Category Order At Main Navigation


The file that controls how the categories are displayed can be founded at: wp-includes/category-template.php

By default, the usage shows:

• No link to all categories
• Sorts the list of Categories by the Category name in ascending order
• Displayed in an unordered list style
• Does not show the post count
• Displays only Categories with posts
• Sets the title attribute to the Category Description
• Is not restricted to the child_of any Category
• No feed or feed image used
• Does not exclude any Category and includes all Categories
• Displays the active Category with the CSS Class-Suffix ‘ current-cat’
• Shows the Categories in hierarchical indented fashion
• Display Category as the heading over the list
• No SQL LIMIT is imposed (‘number’ => 0 is not shown above)
• Displays (echos) the categories
• No limit to depth
• All categories.
• The list is rendered using the Walker_Category class

Around line 412 of category-template.php you can edit how the categories display @ the main navigation bar.

function wp_list_categories( $args = '' ) { $defaults = array( 'show_option_all' => '', 'show_option_none' => __('No categories'), 'orderby' => 'name', 'order' => 'ASC', 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_type' => '', 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0, 'hierarchical' => true, 'title_li' => __( 'Categories' ), 'echo' => 1, 'depth' => 0, 'taxonomy' => 'category' );

So for example, we can display the category navigation ordered by ID instead of by name by changing this line:

'orderby' => 'name', 'order' => 'ASC',

To this line:

'orderby' => 'ID', 'order' => 'ASC',

Here is a list with more commands to tweak:

(string) Sort categories alphabetically, by unique Category ID, or by the count of posts in that Category. The default is sort by category name. Valid values:
• ID – Default
• name
• slug
• count
• term_group

(string) Sort order for categories (either ascending or descending). The default is ascending. Valid values:
• ASC – Default

(string) Style to display the categories list in. A value of list displays the categories as list items while none generates no special display method (the list items are separated by
tags). The default setting is list (creates list items for an unordered list). See the markup section for more. Valid values:
• list – Default
• none

(boolean) Toggles the display of the current count of posts in each category. The default is false (do not show post counts). Valid values:
• 1 (True)
• 0 (False) – Default

(boolean) Toggles the display of categories with no posts. The default is true (hide empty categories). Valid values:
• 1 (True) – Default
• 0 (False)

Much more info can be found at wordrpess website here:

Read more from WordPress

Share your thoughts, post a comment.


Note: HTML is allowed. Your email address will never be published.

Subscribe to comments