May 13, 2013 at 5:14 pm #40739
I'm trying to improve the *nav/subnav* menu presentation using the Prose child theme by hiding empty category menu items. (Google has been particularly unhelpful in this pursuit.)
A project uses a large number of hierarchical categories and subcategories that are bulk loaded and prepared in advance as hierarchical menus. This is done in advance due to the amount of work involved and the need to observe strict hierarchy rules.
Posts are categorized as they are written but this will leave a large number of categories empty for a (potentially long) time and therefore leave a trail of menus that lead to empty category pages.
The Categories widget, for example, hides empty categories from the categories list/dropdown. I would like to do the same with the nav & subnav menus - hide the empty category-menu items until the category is populated with a post that includes it.
Can anyone recommend a method, snippet or plug-in that would alter the navigation menu presentation like this?
May 13, 2013 at 5:58 pm #40751
Can you link to your site please.
How many categories are you needing to hide?
May 13, 2013 at 7:11 pm #40775
Thanks for replying, Brad. The site is currently on a local dev server.
Current estimate for categories is ~225 to ~250. Perhaps half of these will be 'empty' until year 2. "It depends."
May 13, 2013 at 7:27 pm #40782
I think these should be your tags. You shouldn't use that many categories.
May 13, 2013 at 9:49 pm #40818
Thanks for your reco, Brad although I'm not sure of the rationale.
I'm not aware of a performance issue for a volume of tags versus a volume of categories. Although it might be possible to encourage some trimming of the overall count, tags do not meet the hierarchical requirement. There would be typically 3 to 4 categories assigned per post, with additional tagging of perhaps 2 to 5 labels.
Overall, I guess you are saying that there is no way to solve the initial question:
Can one 'hide' empty categories in nav menus until they are used in posts?
May 13, 2013 at 9:59 pm #40821
There is but it might require custom coding as I don't know if there's a plugin for it. I'll let you know if I find a solution.
May 14, 2013 at 11:02 pm #40951
Brad, thanks for looking into this. I think I can say tonight that this has been resolved by using a plugin.
Code would be cleaner and more certain but this should work out fine using the plugin “Add Descendants As Submenu Items” by Alex Mills (Viper007Bond). Alex's page is > here <, at or you can obtain it via the plugin page at WordPress.org.
This escaped my previous searches because it doesn't promise to do what I was seeking ('hide existing categories'), but actually does it a different way in order to achieve a different objective from Alex – automatically add hierarchical items to initialized menus. Alex created it for posts/pages to be added to menus, I can use it to add categories to menus as they are first used.
It took some work to setup and test. I had to destroy a few large menu trees so that the menu items could be added back by the plugin. They aren’t actually added to the menu structure at “Appearance > Menus”, so you have to get the right setup of initial levels of menu structure made by hand so that the plugin can later add to them automatically at lower levels.
This could be a big time-saver for accurately maintaining large hierarchical category > menu structures. I know it will be for me as I won’t have to add and place scores and scores and scores of categories as hierarchical menu items, just add a couple dozen at only two levels deep. With the categories and custom slugs loaded by BulkPress, I’m done!
Thanks again, Brad
And thanks to Alex Mills!
May 15, 2013 at 10:03 am #41027
- The topic ‘Hide empty categories in nav menu?’ is closed to new replies.