http://codex.wordpress.org/Template_Tags/wp_list_cats
No child categories:
<?php wp_list_cats('children=0'); ?>
If subcategories are not indenting, then you’re setting the ‘list’ or ‘hierarchical’ parameter to 0 in wp_list_cats()
, or something in your css is reformatting the category listings.
Thanks for the tip! I updated the code to be <?php wp_list_cats(‘children=1’); ?> and now it’s listing subcategories under the main cats.
Only problem now is that the cats are not in alphabetical order. Any ideas?
Thanks in advance.
“Only problem now is that the cats are not in alphabetical order.”
<?php wp_list_cats('children=1&sort_column=name'); ?>
That should do it.
You are awesome, thanks!!!
Last questions…promise! What if I want categories in a certain order that’s not alpha?
“Last questions…promise!” I’ve heard that one before…
You have several options, all limited in one way or another:
1. Rewrite the underlying code for list_cats (wp_list_cats is what’s known as a “wrapper” to this function). Obviously a choice for PHP-heads.
2. Rename your categories in some fashion to fit the order you want them in. I’ve never liked this one.
3. In the database, under the wp_categories table, rearrange the cat_IDs to the way you want your categories listed, then use ‘sort_column=ID’. With this goes the standard warning: back up your database before making changes.
4. Hope someone made a plugin that does what you want. Haven’t seen one like this.
5. Write the plugin. Again, PHP-head territory.
Thanks for suggesting the various options. I considered both the alpha and changing the IDS. As you said, both have problems. There’s only 8 main cats, but some have many subcats (one has 50 sub cats) and with that many, the subcats need to be alpha.
Rearranging the IDs in the table would work — unless I want to add another subcat later and have it be alpha. Then I’d have to go through that renaming process again, and that would be a headache IMO.
So to make a long story short, I just renamed a couple of the main cats, used the sort by name (alpha) and the order is more to my liking now. This seems to be the simplest and most flexible solution.
Thanks for the help!