0

I have a page that displays information from a query (I placed the output of the query in a custom page template and have the information display that way). How can I put this information into a sidebar widget? Do I need to pull it from the page, or is there a widget that allows you to put a dynamic query inside?

Thanks.

2 Answers 2

1

If you hard-coded your custom query directly in the page template, then you're going to need to duplicate that custom query in a custom Widget.

On the other hand, if you've abstracted the custom query (either into a template-part file, or better yet, a custom function), then you can simply include the template-part file or custom function in your custom Widget.

0

I'd solve this using the Text Widget.

Enabling shortcodes for it:

add_filter('widget_text', 'do_shortcode', 11);

And then, as Chip Bennett points out, using a custom shortcode function that will output your custom query.

3
  • IMHO, this is far more complex (and potentially dangerous) than simply creating a custom Widget... Commented May 25, 2012 at 14:21
  • @ChipBennett - I see... so a better answer depends on the OP showing us his Query, no?
    – brasofilo
    Commented May 25, 2012 at 14:31
  • absolutely :) Commented May 25, 2012 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.