[wp-hackers] Using the_widget() to get a specific instance of a multi-instance widget
jer at simianuprising.com
Mon Aug 9 15:48:14 UTC 2010
On Sat, Aug 7, 2010 at 11:26 PM, Mikel <mikel at mahunneysfarm.com> wrote:
> Trying to use the_widget() to access a specific instance of a
> multi-instance widget and failing miserably.
> Have tried by title and fiddling with variations on array(number=> x) for
> the $instance parameter but
> multiple sidebars is the only way I can get this running successfully with
> the WP Text Widget.
That is a very complicated problem.
One potential solution is to be sneaky about how you set up your sidebars
and display them rather than trying to manipulate individual widget
instances. If you need one text widget to show in multiple places you might
want to break it out of the sidebar it is in and isolate it in its own very
specialized sidebar. Then you call that special sidebar wherever you want
the text widget to show. So maybe you want it at the top of the homepage in
the main content, but then on all other screens you want it at the top of
the sidebar, you just add it before the main sidebar if !is_home(). Breaking
the sidebars up thematically has turned out to be very powerful for me, and
its fully supported by the existing API.
Note that a setup like that will be incoherent to users unless you use the
'description' attribute of the defined sidebars to explain where they will
be shown. Adding detailed explanations there, so that they show on the
widgets screen, lets you do pretty crazy stuff in the templates and as long
as the user reads it they should be okay.
There's no way to limit a sidebar to just one widget using the API
(something that maybe should be remedied, I can think of a lot of uses for a
'limit' argument), but you can demand just one text widget in the sidebar
description in all caps.
Jeremy Clarke | http://jeremyclarke.org
Code and Design | http://globalvoicesonline.org
More information about the wp-hackers