Add Descendants As Submenu Items

When I created the navigation menu at the top of my site using the menu feature in WordPress (Appearance → Menus), I didn’t want to have to maintain anything but the top-level menu items. When I released a new plugin and created a page for it, I didn’t want to have to go into my menu UI and add it there too. So instead I wrote this plugin.

Add Descendants As Submenu Items adds a checkbox to each menu item that is of a hierarchical post type (i.e. pages) or taxonomy (i.e. categories). Checking this box will automatically display all descendants as submenu items on the front end of your site. You can see it in action at the top of my site — I only configured the top level menu items and everything that shows up when you hover over them has been added by my plugin rather than manually by me.

Download:

Screenshots:

79 thoughts on “Add Descendants As Submenu Items

  1. Pingback: New Plugin: Add Descendants As Submenu Items « Viper007Bond.com

  2. Pingback: WordPress Plugin Releases for 9/8 « Weblog Tools Collection

  3. Pingback: Plugin

  4. Pingback: WordPress Plugin ?? 09/08 | AD Nian

  5. Pingback: Translating WordPress Plugin Details « Viper007Bond.com

  6. Pingback: WordPress Plugin ?? 09/08 | My Blog

  7. Great plugin. Would it be possible to automatically add pages based on their categories though?

    So when you create a page/post with a category it gets added to that category of the menu?

    I’ve posted this on the plugin page on wordpress.org as well.

  8. this is exactly what I want but it is not working! I have already made a menu (painstakingly taking forever!) but I still have tons and tons of categories to add and arrange hierarchy….any idea why it is not working for me?

  9. Never Mind….It turns out your plugin is exactly what I have been looking for, if only I had found it 2 hours earlier!!!
    I was in plugin trial mode, and tried this plugin that I thought was going to generate tags based on my categories…but instead it erased my categories and made them tags, when I reversed it the categories did not retain their parent/child relationship, so now I have to go back and redo the parent child relationship for 300 categories….fdsjklsdfjklsdfjkl!!!!!!!!1

  10. Love it! Using it on a large site I am converting from Joomla to WP. This simple plugin, along with the Widget Logic plugin, allow me to do everything the Joomla CMS did and more, as far as menu management, and gets around some severe menu size limitations in WP custom menus (supposed to be fixed in WP 3.3).

    Suggestion:
    With so many using All-in-One SEO pack, it would be nice to have an option on each menu item to specify “Use All-in-One Menu Tags” (if AIO is installed and activated), which would get the AIO menu label and title attributes for the top level post and its child items, and use those in the generated menu items.

    • I have never once used All-in-One SEO Pack and don’t really have any plans to add support for it at this time. I think the plugin is highly overrated and not needed. But that’s a discussion for another day…

      Anyway, my plugin hooks in and adds the dynamic menu items so that they appear to WordPress that they’ve been there the entire time. If All-in-One SEO Pack wants to hook into the menu and add stuff to it, then it shouldn’t have any problems adding stuff to the menu items that my plugin adds either because they should all be the same in the eyes of All-in-One SEO Pack. I’m adding real menu items rather than just some HTML.

  11. Hi, I cannot get this plugin to work. I have installed the plugin, activated it, checked the checkbox (screen shot here: http://www.alexanderb.org/screenshot1.jpg )

    I have created as you can see by the screenshot, a secondary menu which is what I want to be updated. I also have some php code on the page template to determine which menu to show using:

    <?php wp_nav_menu( array('fallback_cb' => '', 'container' => 'none', 'container_class' => 'container_class_name_here', 'theme_location' => 'menu-location-name-here', 'menu' => get_post_meta( $post->ID, 'MenuName', true) ) ); ?>
    

    But I guess thats all on the page side, not where this plugin is getting its information from?

    I of course have the correct parent attributes set on each page.

    I am using wordpress 3.2.1

    Any help would be greatly appreciated!

    Thanks!

    • Just to clear this up, it does work, it just doesn’t show up in the Appearance > Menus panel… I was expecting it to show all the pages within the editabel list rather than simply ticking the plugin checkbox and trusting that it works! Doh! Great plugin!!

      • Yeah, it only takes effect on the front end otherwise it wouldn’t work. They’d all load in, you’d hit save, and then you’d lose the purpose of this plugin because they’d all be hard-coded rather than being loaded dynamically.

  12. I get this error when ever I try to use your plugin

    bytes exhausted (tried to allocate 45615449 bytes) in /home/content/w/e/b/webjazz/html/test/wp-content/themes/Jazzschool_Theme/library/navigation.php on line 329

  13. The plugin doesn’t seem to work with categories as I would expect. In short, I am hoping to have all posts for a specific category automatically show up in a submenu beneath the category menu item. Instead, here’s what I’m experiencing…

    I have four categories for posts, for each of which I have created a menu item in [Appearance>Menus]. For each of the category menus, I have selected to ‘Automatically add all descendents as submenu items.’ The behavior that I expect is that each of the category submenus will automatically display a submenu listing all of the posts for that category. But that’s not happening. Is there any way to use your plugin to achieve the behavior that I’m seeking? Thanks!

    • No, my plugin is trying to list out children categories for each of the categories in your menu. It won’t list out posts for a category.

      My plugin won’t do what you want, although you could use the concepts used in my plugin’s code to write code of your own to do what you’re looking for.

  14. Hi there – love your plugin but yet I’m selfishly trying to make it do one more thing. My client is making month categories and we’d love to be able to order them in chronological month order, as opposed to alphabetically or when the category was added or whatever. I’ve tried one plugin to let me order categories but it doesn’t seem to work while using yours. Any possibility this can be done? Before I go blindly using trial and error to find another ordering plugin that’d work. (Actually, if you do know of a category/subcategory ordering plugin that’d work with yours, I’d love to know which one.)

  15. Can you please add support to display the empty sub categories in the menu as its not showing the sub-categories that have not assigned any post to them.

  16. It could be used to add custom post types items created with MagicFields?
    It would a good point to have the option to set a custom post type to be showed as descendant of a menu item.
    Ie: A page called “services” added in the main menu, and an option to assign a custom type called “Services” to be auto added as descendant items in the Services Main Menu Item.

  17. Hi Alex, I am using your plugin on the wordpress template ” I Love it! ” and it looks like the plugin works but it is not showing the link to the categories :s

    Could you pls help me out :) tnx

  18. Hi Alex,

    Just tried the plugin and it works great on all of my pages except for my home page. The sub-menu shows up when I hover over the top level menu (although the styling isn’t quite right), but as soon as I try to move the mouse off the top level menu and onto a sub menu item the sub menu disappears.

    Any help is much appreciated, thanks.

    • I’ve done a little bit more looking snooping around in the HTML, and it looks like when the menu is working properly, the class ‘sf-menu’ is on the ul and the class ‘sf-with-ul’ is properly on the a tag used for the menu item. But when i’m on the home page (which is a static page) the ul still has the class ‘sf-menu’, but the a tag does not have the class ‘sf-with-ul’

      Any ideas what could be causing this?

      Thanks again

  19. Pingback: INIA | Design | JulioSepia.com

  20. Searched for this plugin for several hours. And finally google helped me to your site. Thanks a ton. I really wished that I could pay you by some click on ads if they appeared on this site. A word of thanks is all that I can offer now. There is a similar plugin called gecka submenu and its features are similar to yours except that you offer taxonomies also for free while they charge for that feature under pro version. Millions of thanks to you once again for being helpful to small site owners like me.

  21. It doesn’t work for me… Am I doing something wrong?
    I installed your plugin and then added all categories I had to the Menu, checking all the “Automatically add all descendants as submenu items” boxes while I did that. But the menu just won’t behave properly… It won’t show any child categories, old or newly created…
    I even tried with a few different themes, but to no avail. (on WordPress 3.4.2)

  22. @Fernando In my view, there could be two reasons why I the child cats are not showing up for you.

    One, you may not have assigned any posts to the categories. If your child category has zero posts, it won’t show up in the menu at all. Try to assign atleast one post to a category and check.

    The second reason could be the way your navigation menu is setup. If you are using wp_nav_menu() then there is a parameter called ‘depth’ which should be assigned to some value. If depth=1 then only one level will be shown. You may find this function in the header.php if your menu is in the header. More about this wp_nav_menu can be found at http://codex.wordpress.org/Function_Reference/wp_nav_menu

  23. Hi,

    First off, awesome plugin! It saved my site from the annoying menu crashes when you have many menu items (50+).

    One feature request, would it be possible to have the option to only include child pages that are 1 step below the parent, i.e. to not include the children’s children? This is because in some places I have these grandchildren pages, but don’t want them to show up in the menu (they are accesable from hyperlinks on the child page). I’m sure I can’t be the only one who would want this.

    I tried doing it myself by editing the plugin, but unfortunately my coding experience with WordPress is not high enough.

    Cheers, Geoff

  24. Pingback: Happy New Year And Welcome To 2012 | Clandestine Laboratories

  25. Hmm, is there any way to make the plugin only add a certain depth of descendants? I tried of course “depth=1″, but all levels still were imported. It would be handy either way to have this option on a per item basis…

    In other words, after the “Automatically add all descendants as submenu items” check box, it would be great to have a “Depth of descendants” option.

  26. Alex Dude,

    Love your ADASI plugin and I’ve translated ALL of its strings into Arabic :D
    Would love to contribute my work, let me know if you accept translations and if so where to send you the .po/.mo files.

    Peace.

  27. Pingback: Changes Over The Last 3 Months | Clandestine Laboratories

  28. Thanks for this plugin, Alex! I literally stumbled upon it. You could add to your post so that it can be found by searching for it for another solution it provides: **hiding empty categories** from big, pre-built nav menu structures until the categories are used.

  29. I’ve installed this on two sites…works great on first one…I agree with everyone else…can’t believe this is not a standard option…anyway, on the other site I am not seeing the check box in the menus that I need to check to activate the plugin…it’s not there for pages, cats or custom taxonomy…any idea what would cause this?

  30. Great plugin! The only thing I’m missing (as some others before) is the possibility to set a maximum depth for the displayed sub-menues. So +1 for this feature

  31. Hi Alex,

    I’ve run into a powerful problem with this plugin: it’s rearranged the world!

    I use this on a site with posts categorized by national hierarchies (eg. North America > USA > Texas).

    Each of the ‘continents’ represent the highest level of menu item, cascading to the nation & region/state.

    However, not all of the subcategories (countries) end up under their parent categories (continents), or states/provinces in the correct country:

    For instance: Australia is placed under Italy when they are peer subcategories under different parent categories. Western Cape (Africa/South Africa/Western Cape) is placed under South America.

    I’ve put up screencaps of the menu structure and the category structures for these examples. Links are on the plugin support page at WordPress.org

    Can you advise or help out? Problem determination?

    Thanks,
    Tom

  32. Love the plugin, it makes it possible for me to add more menu items, because this was limited.

    One question however:

    How do I change the navigation labels of the children and grandchildren?

    Thanks!

  33. Hi Alex, I’m using your plugin for the display of categories as menu items when the categories have associated posts. Works OK-ish, except some menu items are not appearing in the right places. See the site here: http://architourist.ca/

    The actual hierarchical category structure (continents, nations, provinces, etc.) can be seen in the ‘destination’ section in the sidebar: Australia is in Oceania, Western Cape is in South Africa.

    The blue nav menu is built with the ADASI plugin, but this puts Australia in Italy and Western Cape in South America.

    Can you help with some ideas about how this might be corrected? I have previously deactivated and deleted the plugin to try to correct it, but reinstallation brings back the problem. I have a mirror of this site available for you to login and review, test, whatever if you like.

    Thanks,
    Tom

  34. Alex, is it possible to specify a limit for the depth of the children? For example, I want to add only direct children to the menu item but not also children of these children.

  35. Great plugin, Alex. I wasn’t sure at first whether each parent item could have submenus enabled separately, but a quick play with the plugin confirmed this feature. One less thing for the less technically-minded person who updates the site to have to worry about!

  36. Pingback: Using Categories in Navigation Menu for WordPress

  37. Hi Alex, thank you very much, you’ve saved me a ton of work. I’ve rated the plugin 5 stars at wordpress.org where there is a message ‘This plugin hasn’t been updated in over 2 years.’ etc. I have it working on the current WordPress 3.9.2 using Uber menu 3. so it is working. Perhaps you can change the date of the plugin or something to remove the message.
    I have spent many hours searching for a way to automatically add child or sub categories to a top menu item in wordpress. I believe this is the only plugin that will do that.
    thanks again
    Rob

    • Yeah, I need to go through all my plugins and bump their “tested up to” version numbers. I write my plugins well the first time around so I rarely need to update them — they just continue to work fine with new versions of WordPress. :)

      Glad you like the plugin!

Leave a Reply