[wp-hackers] Using the_widget() to get a specific instance of a multi-instance widget

Shawn Parker shawn at crowdfavorite.com
Mon Aug 9 22:41:15 UTC 2010

There's a filter in the `display_callback` method of WP_Widget. It supplies:

	$instance = apply_filters('widget_display_callback', $instance, $this, $args);

Return false on this to invalidate the widget display or modify the $instance args to effect the widget's output.
Is this possibly what you're after?

Shawn Parker
Web Developer
Crowd Favorite
shawn at crowdfavorite.com

On Aug 9, 2010, at 9:48 AM, Jeremy Clarke wrote:

> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list