Community Forums › Forums › Archived Forums › Design Tips and Tricks › Hide empty categories in nav menu?
Tagged: categories, nav menu
- This topic has 7 replies, 2 voices, and was last updated 11 years, 8 months ago by Brad Dalton.
-
AuthorPosts
-
May 13, 2013 at 5:14 pm #40739TomParticipant
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?
thx.
Choose your next site design from over 350 Genesis themes.
[ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ]May 13, 2013 at 5:58 pm #40751Brad DaltonParticipantCan you link to your site please.
How many categories are you needing to hide?
May 13, 2013 at 7:11 pm #40775TomParticipantThanks 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."
Choose your next site design from over 350 Genesis themes.
[ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ]May 13, 2013 at 7:27 pm #40782Brad DaltonParticipantI think these should be your tags. You shouldn't use that many categories.
May 13, 2013 at 9:49 pm #40818TomParticipantThanks 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?
Choose your next site design from over 350 Genesis themes.
[ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ]May 13, 2013 at 9:59 pm #40821Brad DaltonParticipantThere 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 #40951TomParticipantBrad, 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!
Choose your next site design from over 350 Genesis themes.
[ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ]May 15, 2013 at 10:03 am #41027Brad DaltonParticipant -
AuthorPosts
- The topic ‘Hide empty categories in nav menu?’ is closed to new replies.