Frage

I'm using shortcode any widget plugin. Is it possible to send attributes to the widget that is called with shortocde. Something like this

[do_widget name="Category Viewer" maxcount=5]

where maxcount parameter should be used in Category Viewer widget.

War es hilfreich?

Lösung

you can check what attributes the "shortcode any widget" shortcode uses by looking at the following code from that plugin:

extract(shortcode_atts(array(
        'sidebar' => 'Widgets for Shortcodes',
        'id' => '',
        'name' => '', /* MKM added explicit 'name' attribute.  For existing users we still need to allow prev method, else too many support queries will happen */
        'title' => '',   /* do the default title unless they ask us not to - use string here not boolean */
        'class' => 'amr_widget', /* the widget class is picked up automatically.  If we want to add an additional class at the wrap level to try to match a theme, use this */
        'wrap' => '' /* wrap the whole thing - title plus widget in a div - maybe the themes use a div, maybe not, maybe we want that styling, maybe not */
    ), $atts));

so as is - your maxcount attribute won't be extracted from the shortcode by "shortcode any widget".

You would have to modify the plugin code above to support this attribute by adding the maxcount index to the array...

check out the codex for more info on how to work with the shortcode attributes

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top