[Resolved] Dynamic construction of menu trees?

Home Forums Support [Resolved] Dynamic construction of menu trees?

Home Forums Support Dynamic construction of menu trees?

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #333584
    Jay Martin

    I have a situation in which I have to create a menu tree (a single menu item in the Primary Nav menu) that comprises a total of 40 submenu items in 3 layers.

    Almost all of the 40 submenu items have simple, regular productions, making it ideal (and simple) to dynamically generate the set.

    Creating 40 menu items using the standard WP Menu tool would be most laborious. Is there a simple way to generate a menu tree such that it automagically works with all the various forms of menus (site-navigation, sticky-*, mobile, etc)?

    If I have somehow overlooked some obvious documentation, I apologize, and please point me to it.

    Thanks.

    #333603
    Leo
    Staff
    Customer Support

    Hi there,

    I’m not quite sure what you mean? Like a function that creates the menu structure for you automatically?

    If that’s the case I don’t think so…

    If you want all the menus to be the same then you should only have to create the menu once and set it to Primary and Slideout in Theme Locations.

    Let me know if I’m misunderstanding something.

    #333610
    Jay Martin

    Again, I have 40 menu items under one top-level menu item to create. Many of these menu items require backend processing (ie, they’re not simple page/post links, nor simple URLs), but are easily produced using simple production rules in most cases.

    Using the Menu tool, besides being incredibly laborious, requires the use of shortcode support (I use the “Shortcodes in Menus” plugin). I was hoping to improve performance and make life much simpler by just creating the menu tree on the fly, then adding it to various menu locations.

    I have done considerable reverse-engineering on the form and structure of the menus generated by GP for the main site-navigation menu, but I am concerned about the other menus involved, such as the sticky menus and the mobile version.

    So, I am looking for a way to hook into GP’s menu construction mechanism to ensure my menu tree is properly inserted (and rendered viz CSS) in all the related menus.

    WP has quite a nice open API for adding things to the Admin Toolbar menu, and I was hoping GP had something similar, although I am fully aware that a typical Theme’s menu construction rules are necessarily more complex owing to the fact that several incarnations of a given menu item are placed in various menus (again, the sticky menus, the mobile menu, etc).

    Am I asking for too much here?

    #333620
    Leo
    Staff
    Customer Support

    I will ask Tom to have a look ๐Ÿ™‚

    #333622
    Jay Martin

    Thanks. I don’t want to “push” you fine folks, but I need to get rolling on this task, but would rather wait until I hear back from the developers before I launch off into additional reverse-engineering to see if I can hook into the Theme or not.

    Thanks, Leo.

    #333752
    Tom
    Lead Developer
    Lead Developer

    GP just uses the WP menu construction, so there’s no real way to do this that’s GP specific.

    As far as I know, the only way to automatically add pages is the “Automatically add new top-level pages to this menu” option, but as that says, it should only take care of top-level pages.

    Another option is keeping the theme location un-set, which will then display ALL pages on your site, and show the sub-menus based on the page parent connection. Again, not really ideal.

    #333755
    Jay Martin

    So are you saying that GP doesn’t do anything special in terms of constructing the physical menus based on the menu definitions and prescribed locations, that GP delegates all menu construction to the core WP?

    #333764
    Tom
    Lead Developer
    Lead Developer

    It depends what you mean by construction. GP sets the HTML classes/IDs of the container, but the actual structure of the menu items is all WP.

    #333776
    Jay Martin

    Can you save me some time reverse-engineering the code and perhaps point me to where said construction is performed in the GP code base?

    Thanks.

    #333778
    Tom
    Lead Developer
    Lead Developer
    #333933
    Jay Martin

    Thanks for the pointer, Tom.

    So if I understand you correctly, GeneratePress does not in any way get involved with the definition and construction of the actual menu items, instead letting stock WordPress handle it. GP may handle such things as sticky menus and various rendering (CSS) attributes (based on the user’s settings in the Customizer), but that’s about it.

    At this point I’m going to mark this topic as “Resolved”, but I may come back later and add any info I find useful to this discussion, for posterity’s sake, especially if I can find a way to cleanly export/import Menus in a safe and effective manner.

    As always, I appreciate your exceptionally rapid response. Thanks!

    #334070
    Tom
    Lead Developer
    Lead Developer

    That’s correct. Things like the sticky menu etc.. just attach to the class given to the main navigation element.

    No problem! ๐Ÿ™‚

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.