On a recent WordPress Network (WPMU) project, I’ve needed to display the same sidebar and associated widgets across all the sites in the entire network.
Since switch_to_blog()
has been deprecated and an attempt at monkey-patching sent me deeper into the bowels of WordPress than I felt was warranted…
I turned all the necessary widgets into pages and used get_blog_post($blog_id, $post_id)
to build the widgets by hand.
<?php $posts = array(5304, 5322, 5309, 5310, 5301, 5299); foreach ($posts as $post_id) : ?>
<?php $post = get_blog_post(1, $post_id ); setup_postdata($post); ?>
<div class="widget">
<h4><?php the_title(); ?></h4>
<div class="textwidget">
<?php the_content(); ?>
</div>
</div><!-- widget -->
<?php endforeach; ?>
The downside – widgets need to be manually added, moved, and removed from the array.
The upside – it works.