WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using 3.0b1 menus for multisite navigation (14 posts)

  1. johnrork
    Member
    Posted 4 years ago #

    I'm planning on using dynamic menus for navigation across a primary blogs and sub-blogs with the same theme; however, menus are confined to the blog in which they are created.

    Is there a way to pull a primary blog's menus into a sub-blog?

  2. No. They're like widgets - Confined to their own blog.

  3. johnrork
    Member
    Posted 4 years ago #

    Can't there be a way to do this programmatically in the theme? To temporarily step out of the current blog and load a menu as if it were a different blog, then back again?

    Something like WPMU's switch_to_blog() function?

    I realize that the menu wouldn't appear in admin... that's actually the desired effect: all of the functionality, none of the control ;)

    Obviously, this would require sub-sites to use a child theme; that is no problem.

  4. You can put that in as a feature request, but right now there isn't. Though that said, if you're having subsites use a child theme anyway, you may be better off doing this via a functions.php file in the parent, have THAT control the menu.

    I keep thinking about how you'd do this, to handle both MultiSite and Stand Alone, and I come up with a lot of contradicting answers! On one hand, it's a perfect example of how MU should have master level administration, but on the other, if I was running multiple domains off one site, I wouldn't want this at all. Argh.

  5. johnrork
    Member
    Posted 4 years ago #

    To me, it seems that menus—which are likely to contain navigation—should be handled in the same way as plugins, which have an "activate" and "network activate" options.

    you may be better off doing this via a functions.php file in the parent, have THAT control the menu.

    Care to elaborate on that? I mean, I am currently using widget areas and navigation menu widgets. The widget area is declared in the functions.php file, but the corresponding widgets are only available to the blog in which they were created.

  6. To me, it seems that menus—which are likely to contain navigation—should be handled in the same way as plugins, which have an "activate" and "network activate" options.

    Except that not everyone uses MultiSite. And not everyone uses MultiSite that way. I agree, some of us want multiple blogs, all with the same (or VERY similar) layouts and, in that case, it's a mother to get all your widgets the same on all blogs. In other cases, for example, I run a MultiSite where each and every blog has it's own design (one garish, one simple, one bog standard, etc). And then there are people who have multiple DOMAINS, and there shouldn't be standard navs for all of them.

    As a sidebar - "network activate" just means 'This plugin is turned on for all blogs.' The settings for each blog STILL need to be customized per blog. So ... there's that.

    Anyway, my idea about the functions.php is a little unspecific, since it's theory right now. If you defined your nav menu as a function (li and ul and all via echo) and then called it as an add-action to the widget area, it SHOULD put the code in. Then it's just a matter of CSS styling. This is all entirely untested, but in THEORY it's how a lot of parent themes work, so I'm pretty sure it can be done. I'm just not 100% crystal on HOW :/

  7. this sort of thing is definitely plugin territory,. Not every wants or needs it, and done wrong, it can be a real drain on system resources.

    Like this is how we do it in MU:

    just before the nav bar code in your theme's header.php put
    <?php switch_to_blog(1); ?>
    right after the navbar code put
    <?php restore_current_blog(); ?>
    then it will always show the pages from Blog #1.

    But switch_to_blog can get expensive when you have a lot of blogs and I am not sure if this function has the same name in 3.0. Might as well try.

  8. johnrork
    Member
    Posted 4 years ago #

    Sorry, I guess I a follow-up is in order!

    switch_to_blog() is indeed alive and well in 3.0.

    It did not do exactly what I wanted, as I planned to use menus in widget mode for ease of administration, and you can't load a widget area via switch_to_blog().

    However, loading them via wp_nav_menu() did work, and only cost the ability to easily change menu order. All in all, it was a good compromise.

    Thanks for the help!

  9. skrebs
    Member
    Posted 3 years ago #

    johnrork - I am trying to do this exact thing and I was wondering if you could possibly give a little insight as to how you accomplished this using wp_nav_menu()?

  10. Justin Sternberg
    Member
    Posted 3 years ago #

    worked awesome... thanks Andrea_r and johnrork.

    my code in my custom header:

    <?php switch_to_blog(1); ?>
    <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'menu-name' ) ); ?>
    <?php restore_current_blog(); ?>

    my code in functions.php

    <?php
    add_theme_support( 'menus' );
    	register_nav_menus( array(
    		'menu-name'' => __( 'Menu Full Name', 'my_theme_name' ),
    	) );
    ?>
  11. MaxOnTheHill
    Member
    Posted 3 years ago #

    Question - could you wrap your whole header in:

    <?php switch_to_blog(1); ?>
    -- my header code here --
    <?php restore_current_blog(); ?>

    to have the whole header area the same as the first blog?

  12. MaxOnTheHill
    Member
    Posted 3 years ago #

    @jtsternberg thanks for posting your results.

    While I understand the code in the header, what is the code in functions.php for?

  13. Justin Sternberg
    Member
    Posted 3 years ago #

    ha, i don't know why i put that, but i ended up deleting it. It's not needed. oops.

  14. johnstalnaker
    Member
    Posted 3 years ago #

    Andrea - thanks for posting the <?php switch_to_blog(1); ?> it took me forever to find this thread but it was exactly what I was looking for. I hope WP adds a "global nav" feature for network sites, but this switch worked wonders.

Topic Closed

This topic has been closed to new replies.

About this Topic