Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
IMHO, this is far more complex (and potentially dangerous) than simply creating a custom Widget... –  Chip Bennett May 25 '12 at 14:21
    
@ChipBennett - I see... so a better answer depends on the OP showing us his Query, no? –  brasofilo May 25 '12 at 14:31
    
absolutely :) –  Chip Bennett May 25 '12 at 14:31
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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