Add widgets to all subsites
I am using the Twenty-Ten Theme in a multisite environment.
On the mainsite (xxx.yyy.com) I have activated a few footer widgets. I want these widgets to be shown on all subsites (subsite1.xxx.yyy.com, subsite2.xxx.yyy.com, etc.)
How can I achieve this?
If you want the content of those footer widgets on all subsites, the easiest way is to hardcode the widgets into the footer template file. Otherwise, you’d need place the widgets manually on each subsite.
Tim, thanks for your answer.
I am using the Text Widget. How do I hardcode that widget in the template?
You’d have to take the content of the text widget and place it in the footer.php file of your theme. You’ll have to do some trial and error work to make sure it gets to the right place.
Ok, but that’s just hardcoding the content of the widget in the template. I want the widgets to be inluded in the template, so that if I make any changes to the widget content, it is reflected on all subsites.
I just don’t want to advise my customer to edit a templatefile if he wants to change some text.
Well, widgets are intended to be per-site, not site-wide.
Depending on what you are trying to do and how often you want to update, you could probably do a template tag and a site-wide option parameter.
This (http://wordpress.org/extend/plugins/wp-announcements/), I think, is similar to what you want to do. You can take a look at what they are doing and modify it to suit your needs.
Or you could wrap the footer in:
<?php switch_to_blog(1); ?> //widget stuff here <?php restore_current_blog(); ?>
but I would only do this on a network with a small amount of sites. < 10
Andrea, thanks for your answer, I’ve added this:
switch_to_blog(1); get_sidebar( 'footer' ); restore_current_blog();
But that doesn’t seem to do the trick, what am I doing wrong?
I used “default blog” plugin to create a blog template for every subsite that is initiated. It is a really handy plugin.
mbootsman – You could try hardcoding the widget itself in the theme (using the
the_widget()template tag), but I haven’t played much with that, so I’m not sure if will pick up the appropriate settings for the widget or not.
thanks for your reply.
In my mainsite I have dragged two Text widgets to a sidebar. I have given them a title and content. Now, how can I, with use of the
the_widget()code, call these widgets in my footer template?
I came this “far”:
the_widget('WP_Widget_Text');but that doesn’t work. I think I need to call the widgets by there id, or instancename, but where do I find that?
I think the
the_widget()function is meant to act as kind of a replacement for the dynamic widgets; so dragging and dropping them has nothing to do with using
In the case of the Text Widget, the “instance” argument is basically looking for an array of “title” (the title you want to appear at the top of the widget), “text” (I believe this is where the content of the widget goes) and “filter” (looking at the source for the text_widget, it looks like this is a boolean indicating whether to apply
wpautop()to the content or not).
Therefore, you would use something along the lines of:
<?php $mywidgettext = '<p>This is the text of my widget. This should appear where it\'s called'; the_widget('WP_Widget_Text',array('My Text Widget',$mywidgettext)); ?>
to display the widget wherever you wanted it.
Since you want to be able to easily modify the content of the widget without having to modify theme files, you could conceivably put the content of the widget in a separate file, then pull it in as a variable into your theme.
That might look something like (assuming your widget content is stored in a file called “mytextwidget.php” in the root of your WordPress installation):
<?php $mywidgettext = file_get_contents( ABSPATH . 'mytextwidget.php' ); the_widget('WP_Widget_Text',array('My Text Widget',$mywidgettext)); ?>
- The topic ‘Add widgets to all subsites’ is closed to new replies.