I use wp_list_categories()
to get the list of all the categories and generate the navigation bar. Is there a way to order these categories in a particular order other than alphabetical ordering.
eg: Connect, News & Views, Q&A, Hello Startup, Startup 101…
Most themes don’t use the description of the category for anything. Easy workaround I did was to use numbers in description. The top post here currently has some jQuery hack from here, it’s unneeded.
You can add custom order fields I suppose as well.
Just
Technical approach
The problem in wordpress core is that the table
wp_terms
has noterm_order
column. That means, standard wordpress does not support the custom term order. If you look at this WP database structure you can find the tablewp_term_relationships
. This table is responsible for the relationships between posts and the taxonomy (your categories) AND this table has aterm_order
column.Now, with a simple SQL statement
ALTER TABLE wp_terms ADD term_order INT(11) NOT NULL DEFAULT 0
(not forget the$wpdb->wp_terms
variable) you can add a column to the table, which is responsible for your custom category order. Then you can put your custom category order in this two columns ofwp_term_relationships
andwp_terms
. When all is finished, you can hook into the filter ofget_terms_args
and change theorderby
toterm_order
.Here a list of all relevant links for the technical approach:
$wpdb->wp_terms
A plugin can do the job for you
Check my plugin to solve this: WordPress Real Categories Management. WP RCM creates an extra field term_order on the wp terms table. It also brings a lot of other useful features as you can see in the screenshot below. It allows you to organize your wordpress categories in a nice way. It is easy to use, just drag&drop your categories and move it to a specific order. The plugin works in all Custom post types.
From the product description i can quote. If you want to try the plugin, there is also a demo on the plugin page.
There are a lot of free plugins
This can be solved with a lot of free plugins available within the wordpress.org plugin repository. Simply search for “category order” in your WordPress Dashboard > Plugins > Install.
This is inbuilt in
wordpress_wp_list_categories
I think that would help you out
I did it generating several term lists. I call it later by my own order. I’m a PHP beginner.
First, I store, in a different variable, the ID for each category term:
Then, I create several args for each
wp_list_categories()
excluding, with this variable the terms I want to:Finally, I can call separately each term list:
Use Category Order and Taxonomy Terms Order free plugin
I didn’t find anything so I constructed my own method. I abstracted it away in an abstract class for my plugin, hence the extra code, but you can pull the methods.
The main method to look at is
format_hierarchy()
Right after registering the custom taxonomy I call
TaxonomyProductService::define_taxonomy( ‘url-slug’, ‘product-service’ );
And finally how it’s used
For the benefit of future visitors, here’s the easy solution to this problem:
There are now a number of plugins that allow you to order categories or other custom taxonomies in WordPress. You can see some of them in the WordPress plugin directory’s “category order” tag page. I can personally confirm that Custom Taxonomy Order NE plugin does the job.