• So, I am hoping to have a conceptual discussion here regarding navigation as it relates to multi-site.

    I understand the idea behind a multi-site installation is to allow users to have their own installation of wordpress without having to maintain many installs.

    In our case, we are a higher ed institution, and each department within the school (admissions, academics, research, etc) will be provisioned as their own site from the main site.

    The development is going very well, but I have hit a wall that I fear will de-rail the entire project.

    The wall, is our navigation. I would like the navigation to be controlled, 100%, from the main site, where only a few people will have access. Each site might be assigned to an area, to give the appearance of a hierarchy. For example, I might have 5 sites that are assigned to the “Research” area, and then only 1 site that is assigned to the “Admissions” area (this is a pretty close approximation of our use-case).

    I am comfortable maintaining multiple menus within wordpress for each “area”. The problem I am running into, however, is that those links have to be “Custom links” and do not allow you to have any hierarchy. So, for example, if I nest a link inside another link, and then on the front-end, click on the parent link, it does not show the sub link below it.

    I have racked my brain trying to come up with a workable solution and even scoured the internet. However this is such a unique use-case that information for it is really not that much help.

    I have considered using a custom walker class, but even that doesn’t solve the problem of “opening” the navigation structure.

    The website I am converting is here: http://goo.gl/9WXsh If you dive into the main nav, you’ll notice that research has a different left nav than does admissions, or academics, or even alumni. That’s the functionality that I am hoping to mimic.

    Sorry for the long post. If anyone has any insight, I would greatly appreciate it.

Viewing 11 replies - 1 through 11 (of 11 total)
  • So, for example, if I nest a link inside another link, and then on the front-end, click on the parent link, it does not show the sub link below it.

    do you really mean when you click that link, you go to the sub site and the menu is not the same there?

    Thread Starter Aaron Wagner

    (@ajwagner777)

    Well, no I have accounted for that by switching to the main blog before I get my navigation. Each site will have similar navigation, with the one exception of the left nav, which will need to be chosen dynamically, based on selections I will make on my dashboard theme options.

    Interesting. We are facing a very similar philosophical discussion while developing the themes for our new site at UMW. In our case, we will have a static navigation bar that will appear on all of our top-level and level 2 sites.

    In our case, our current plan is to manage the list of “sites” (or “blogs” in the old WPMU lexicon) that need to show up in the navigation bar from our main site (the site with a blog ID of 1).

    Then, our theme will dynamically pull the list of child pages from the database (using $wpdb->set_blog_id to loop through the selected blog IDs, then running a query directly against the database to pull all posts with an empty parent ID) and output them in the appropriate places within the menu. Of course, in order to improve performance, we plan to cache those menus in some way after we pull the information from the database.

    This is not a perfect solution (for one thing, it will be difficult to dynamically build the permalinks for each, so you’ll need to either output the shortlinks in the menu or you’ll need to have the permalink settings set consistently across all of your sites and sort of build the menu links based on a hardcoded permalink structure), but it should at least help get the job done.

    Unfortunately, I’m not aware of any simple way to manage WordPress custom navigation menus (the ones you manage through Appearance -> Menus) from one site and use them on another site. There is just too much processing that goes into building those menus to try to pull them across sites efficiently.

    EDIT – You responded to Andrea while I was writing my post. I noticed you said that you’re switching to the other site. Are you using switch_to_blog() to do so? If so, that’s eventually going to really hinder the performance of your site after a while. switch_to_blog() should only very rarely ever be used on the front-end of a WordPress site (it sometimes makes sense on the backend). If you are using switch_to_blog() on the frontend, and you feel the need to continue doing so, you really need to consider caching the information you pull during that switch so that it doesn’t have to run every time a page is loaded.

    Thread Starter Aaron Wagner

    (@ajwagner777)

    Actually, the last thing you mentioned is the easy part:

    function get_sph_nav($menu,$leftMenu='')
    {
    	switch_to_blog(1);
    	$returnMenu = wp_nav_menu(set_menu_options($menu,$leftMenu));
    	restore_current_blog();
    
    	return $returnMenu;
    }

    That gets the nav from the main blog and returns it. I have many menus, so, hence the function. set_menu_options simply returns an array of arguments.

    I was just thinking about this, and I think what I will have to do is write some custom queries that looks at the URL and then gets the appropriate navigation tree. Once I have that, I can use a walker class to iterate through the array.

    Again, though, you really should try to avoid using switch_to_blog() anywhere on the frontend of your website. It is a very expensive function and could potentially cause serious performance issues when you start to get a decent amount of traffic.

    Thread Starter Aaron Wagner

    (@ajwagner777)

    I am not terribly concerned with it at this point, as we will be doing some heavy caching once we go to production. Right now the switch function executes in 0.00076889991760254 seconds. That’s within the acceptable range for me.

    Global nav menu without switch_to_blog (which is an admin function) and also caches:

    http://wpmututorials.com/plugins/networkwide-menu/

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    switch_to_blog() can have the weird issue of mucking with your caches (like not resetting caches between blogs well).

    Thread Starter Aaron Wagner

    (@ajwagner777)

    I had hoped that this would not become a discussion about switch_to_blog(), but rather to deal with the original question: What is the best method of having a network wide menu, complete with hierarchy. The link that Andrea sent does only half the job. The hierarchy is the really important part. The problem remains that I cannot “drill into” navigation with custom menu items.

    I am going to be investigating some queries today to pull my navigation tree based on the current location.

    One side note (since we were talking about switch_to_blog()): the codex makes no mention of this function being administrative in nature. It’s highly likely that I am using other functions through my site that are also “administrative” as well. Would it be possible to somehow flag which functions are meant for front-end use and which ones are solely for admin use? The afore mentioned function’s codex page (http://codex.wordpress.org/WPMU_Functions/switch_to_blog) seems to be written from a “front-end” point of view; talking about pulling posts from other blogs, and such. Just a thought. This is my first MAJOR WordPress site, so I am relying heavily on the codex.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    You cannot possibly expect to have a discussion involving ‘best methods’ without people pointing out why something is NOT a best method. You asked for best, we wanted to warn you about problems with what you decided on. This is called being helpful 🙂 (The codex is a bit out of date, and switch_to_blog() has been deprecated and needs to be rewritten. And now the codex has a warning.)

    Going back to what you’re talking about for hierarchy…

    So, for example, if I nest a link inside another link, and then on the front-end, click on the parent link, it does not show the sub link below it.

    Do you want it to?

    This strikes me as just a matter of layout and css-ing, but I get the feeling I’m missing something in your explanation. I looked at the example site, and they just have different menus per site. If I needed people to be local ‘admins’ but not mess with menus, etc, I’d probably use a role manager plugin and make something called ‘Local Admin’ and just revoke menu/theme changes from that role.

    The problem remains that I cannot “drill into” navigation with custom menu items.

    If you’re having issues with menu drop downs and custom links… this seems more like a custom menu issue then.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Subsite navigation’ is closed to new replies.