• I’m currently developing a website where the parent theme and child themes are very similar. I want the parent theme’s widgets to be editable by the network admin, however I want those widgets to also display in the same position on the child theme, not editable by those users.

    What I need is a way to get the dynamic_sidebar() function to not only pull from a position, but from the parent theme as well. This will be an ideal solution as I will only have to change a very small amount of files in the child theme.

    Any ideas on this? With child themes gaining popularity it might be a good time to consider expanding the dynamic_sidebar() function to:

    dynamic_sidebar($index, $theme);

    I could then write a new functions.php file in the child theme to prevent administrators of the child themes to make any changes to those widget positions.

    Or maybe there is an easy way to do this already?

    I appreciate the help.

Viewing 15 replies - 1 through 15 (of 17 total)
  • I’d make them not widget and hardcode them in the sidebar. Like we did sidebars before widgets. šŸ˜‰

    So call template functions * outside* the dynamic sidebar area.

    Thread Starter skyer2000

    (@skyer2000)

    That unfortunately will not work, since they need to be editable by the network admin.

    Here is a more clear description of the result I’m trying to figure out:

    -Network Admins can change the widgets on the parent theme
    -Those widgets then display on the child theme
    -Site Admins cannot change the widgets on their individual websites

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    šŸ³ļøā€šŸŒˆ Advisor and Activist

    You COULD do that with some fancy switchtoblog calls, but that would introduce layers of latency I’m not sure you want.

    Do they HAVE to be separate sites? Maybe you could do this with CPTs instead?

    Thread Starter skyer2000

    (@skyer2000)

    If this would work, then it would be perfect.

    switch_to_blog(1);
        dynamic_sidebar('home_side');
    restore_current_blog();

    And yes, they do have to be different sites. The employees can create their own set of pages and manage their own blog.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    šŸ³ļøā€šŸŒˆ Advisor and Activist

    That should work, actually. In theory.

    The problem is switch_to_blog becomes computationally expensive.

    the down side of switch is that it’s an expensive query, especially on the front end, and will bog down the more sites you add.

    Just so you know that up front.

    Thread Starter skyer2000

    (@skyer2000)

    That’s interesting that it would be considered an expensive query. I would imagine it just uses that ID number set in switch_to_blog to populate the ID number in dynamic_sidebar().

    There will be around 50 sites, is this something that will bring it all to a crawl? Even with something like hyper-cache installed?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    šŸ³ļøā€šŸŒˆ Advisor and Activist

    Short answer: The more database calls you make, the more ‘expensive’ things get, resource wise.

    It’s hard to say if it’ll kill you or not. I seem to recall that using restore_current_blog(); used to dump my cache (I use W3TC) so I stopped using it at all.

    it’s really only meant for internal or admin area functions. technically, it’s a deprecated functions but there’s no replacement for it so people still use it.

    Are you doing this within the same *theme*? You keep saying parent.child theme and not main/sub site with the same theme.

    Thread Starter skyer2000

    (@skyer2000)

    Yes sorry for the confusion, I’m using Parent/Child themes for Main/Sub-Sites.

    I feel this is a missing feature in WordPress. There really should be a way to use Widgets from the Parent/Main site on Child/Sub-Sites. This gives the overall administrator of the site the power to fill in widget areas for the sub-sites. At this moment it does not seem possible (unless everything is hard coded).

    The only other way I can think to do this is using iFrames. I could create template fills in the parent theme that only display the widget and nothing else, then pull up those pages using iFrames. Not an elegant solution but it would work.

    Each site in the network is intended to be separate *without* sharing. That’s why it’s not there.

    THe main use case for multisite is to build something like wordpress.com & host blogs for people.

    Thread Starter skyer2000

    (@skyer2000)

    WordPress was intended to be only a blogging platform, but that is no longer the case!

    This feature gives the network admins an even larger amount of control that is especially useful for many types of corporate sites that allow their employees to manage their own sub-sites. This new feature expands the use case for multisite into something much more.

    Yes, I know. šŸ™‚ I’m well aware of how much you can do with it, I’m just giving the philosophy about the actual devemopment and the use case the devs keep in mind when they make decisions like “sidebars and widget areas are on a per site basis”.

    That’s why it’s hard.

    Personally, I’d hard code it and if someone on the net admin level needed something changed then the sidebar would have to be edited. A smart dev would make a text box in the admin area. šŸ˜‰

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    šŸ³ļøā€šŸŒˆ Advisor and Activist

    You could put that plain text file in the parent theme folder, and then use the theme editor (only available to super admins) to edit it.

    Thread Starter skyer2000

    (@skyer2000)

    Unfortunately the client’s description does not match any of the proposed solutions. If this were my own site I would definitely hard-code these into sidebar files.

    One last idea before I give up on this and go back to the client:

    Part of good MVC frameworks is the ability to use a controller to render and include view files. Can WordPress do this?

    For example, I have a page located at http://mysite.com/widgetpage that renders and only displays the widget. I did this by creating a template file that only displays a widget position and nothing else, then created a blank page using that template file on the parent site.

    Now when I work with template files on the child theme/sub site, is there a function I can use that first renders that page in wordpress, but then includes it directly on the page? I tried using the php function include(), but that is not working because of the way WordPress disguises the links.

    Maybe a better question is to ask if there is a direct link I can reference to a specific WordPress generated page VIA include()?

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘How to get a Child Theme to use the Parent Theme's widgets’ is closed to new replies.