WordPress.org

Ready to get started?Download WordPress

Forums

Can you change global $blog_id to 1 and then back again? (4 posts)

  1. carl-johan
    Member
    Posted 3 years ago #

    Hi

    I have created quite a large main menu on my main site, which I'd like to use on all sub sites as well, and I rather not duplicate it on all 16 sub sites manually. I can't use the solution suggested here (http://dustyreagan.com/global-page-navigation-accross-wordpress-mu-blogs/) because I'd like to use wp_nav_menu for my main menu and the wp_list_pages for a site specific sub menu (and wp_list_pages is filtered in that hack).

    An idea I have is if you can overide the global $blog_id in a loop and then reset it again (after calling wp_nav_menu in between). Not sure if a set up like that is possible or if that will break the site?

    What I'm suggesting is something like this;

    1. update global $blog_id = 1

    2. call wp_nav_menu (while site in identified as ID=1)

    3. reset global $blog_id to it's original value (e.g. the current sub sites ID)

    Again, this might be an absolute no-no.

    Another suggestion would be to create a duplicate function of wp_nav_menu in the themes functions.php and change something in that function (what DB table is chosen, I guess is what would need to be changed) - much like the hack above. It just seems like harder work, if what I thought of is at all possible.

    Would be very grateful for any insight to this issue, even if it's that I'm an idiot and should leave it be :)

    Thanks in advance.

  2. switch_to_blog is the function.

    It's expensive, as in resource intensive, especially after you get a number of blogs in there.

  3. honewatson
    Member
    Posted 3 years ago #

    I would maybe store the menu as html in wp_sitemeta db table if its the same html every time.

  4. carl-johan
    Member
    Posted 3 years ago #

    Thanks for your replies, sorry for the overdue answer, busy weekend.

    "Switch_to_blog" sounds like the function I need then, but with 16 or so sub-sites, that might not be a good idea if it's a heavy call?
    What the best way to evaluate that? Sorry, but I'm really a beginner when it comes to that part of the development, e.g. checking the loading time/database calls etc, but if you can just tell me what it's called I can google it for myself.

    I could hard code the menu into the theme as well, though it is in 3 languages using WPML so it needs to check what language is currently active etc. That or storing it in wp_sitemeta (thanks for that one btw, never seen it before) will be my last resort, but I'd like to keep it editable through the admin panel if possible.

    Thanks again for your answers!

Topic Closed

This topic has been closed to new replies.

About this Topic